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!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.