0

I'd like to check if a value is already in the table. The structure of my table is this:
ApplicantId = INT
EventId = INT
StudentId = INT

No need to use unique because these table has dependencies.

Below is what I have tried so far:

include('../connectdb.php');

$ScholarPointId = $_GET["ScholarPointId"];
$Point = $_GET["Point"];
$ScholarId = $_GET["ScholarId"];
$EventId = $_GET["EventId"];

$verifysql = mysql_query("SELECT EventId FROM scholar_attended_events WHERE ScholarId ='$ScholarId' ");

#$resultVerify = mysql_fetch_assoc($verifysql);
$num_rows = mysql_num_rows($verifysql);

if( $num_rows > 0 )
{
 $script = "<script>
     alert('The user has already attended this event!');
            </script>";
 header('updatescholarpoints.php');
 exit();
}
else{
$result = mysql_query("UPDATE scholar_points 
SET scholar_points.Points = 
scholar_points.Points + $Point  
WHERE scholar_points.ScholarPointId = '$ScholarPointId' ") or die(mysql_error());

mysql_query("INSERT INTO scholar_attended_events (EventId , ScholarId) VALUES( '$EventId' , '$ScholarId' ) ") 
or die(mysql_error());  

}

?>

What I want is to check if the EventId is already in taken by the Student = StudentId. If so, then system will prompt an alert box. Otherwise, Update and Insert into respective table. How can I do this? It seems I miss something in here. If you could help, I really appreciate it.

4

1 に答える 1

1

=?_

$verifysql = mysql_query("SELECT EventId FROM scholar_attended_events WHERE ScholarId =$ScholarId ");

(そしてPDOまたはmysqliを使用すると、コードは実際には非推奨のモードになっています)

于 2013-01-10T16:23:55.273 に答える