Jump to content

Adding information into database with drop down selection


tang28

Recommended Posts

Hey i am having problems with inserting my data from a drop down into mysql database, basically what i am trying to do is to insert score, place, memberID, event ID INTO a table called "results"

 

This table has 4 colums! Score, Place, EventID, MemberID.

 

what i am trying to achieve is to insert data based on the eventID clicked on given by the query string: Assignment2/RecordResults.php?event=3

 

but i am getting this error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') WHERE (eventID= NULL)' at line 1 

 

here is the code:

 

 

	  	$pdo = new PDO('mysql:host=127.0.0.1;dbname=clubresults', 'root', '');

	$result = $pdo->query ('SELECT MemberID, Firstname, Surname FROM members');

		echo '<select name="memberID">';

		foreach ($result as $member)
		{
			echo "<option value=\"{$member['MemberID']}\">{$member['Firstname']} {$member['Surname']}</option>";	
		}
			echo '</select>';

    $errors = array();
    
      $eventID= $_GET['event'];
      echo $eventID;
      
	if (isset($_POST['score']))
		{
            require 'validate.inc';

		    validateScore($errors, $_POST, 'score');
		    validatePlace($errors, $_POST, 'place');

			if ($errors)
				{ 
				  	require 'RecordResultsForm.inc';
			  	}
					else
				{				

				$pdo = new PDO('mysql:host=127.0.0.1;dbname=clubresults', 'root', '');

				$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				try 
				{


				$stmt =$pdo->prepare ('INSERT INTO results (Score, Place, MemberID) VALUE (:score, :place, :memberID,) WHERE (eventID= :event)');



		       	$stmt -> bindValue (':score',$_POST['score']);
		       	$stmt -> bindValue (':place',$_POST['place']);
	       		$stmt -> bindValue (':memberID',$_POST['memberID']);
	       		$stmt -> bindValue (':event',$_GET['event']);
    				$stmt ->execute();
				}
		        	catch (PDOException $e)
					{
			        echo $e->getMessage();
				}       
         			    
         			    require 'RecordResultsForm.inc';
         			    echo "<br/>";
      					echo 'Form submitted successfully with no errors!';
			    }
    	}[size=8pt][/size]
    		else
	        require 'RecordResultsForm.inc';
	          
        echo "<br/>";
        echo "<br/>";

Please i need help!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.