tang28 Posted May 29, 2012 Share Posted May 29, 2012 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!! Quote Link to comment https://forums.phpfreaks.com/topic/263308-adding-information-into-database-with-drop-down-selection/ Share on other sites More sharing options...
tang28 Posted May 29, 2012 Author Share Posted May 29, 2012 Anyone? i am new to SQL and php and this assignment is due in 2 days! any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/263308-adding-information-into-database-with-drop-down-selection/#findComment-1349430 Share on other sites More sharing options...
Pikachu2000 Posted May 30, 2012 Share Posted May 30, 2012 The error message generally pinpoints the spot the error occurs. I'd be suspicious of the extra comma just before the closing parenthesis. Quote Link to comment https://forums.phpfreaks.com/topic/263308-adding-information-into-database-with-drop-down-selection/#findComment-1349696 Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2012 Share Posted May 30, 2012 Also, insert queries don't have where clauses. Quote Link to comment https://forums.phpfreaks.com/topic/263308-adding-information-into-database-with-drop-down-selection/#findComment-1349697 Share on other sites More sharing options...
fenway Posted June 2, 2012 Share Posted June 2, 2012 Also, insert queries don't have where clauses. Sounds like the OP wants an UPDATE. Quote Link to comment https://forums.phpfreaks.com/topic/263308-adding-information-into-database-with-drop-down-selection/#findComment-1350642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.