andrew6607 Posted December 17, 2007 Share Posted December 17, 2007 PHP Version: 5 Mysql Version 5 Error: INSERT error: 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 ' , , , , , )' at line 2 Here is the code im using. <?php $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $positon = $_POST['positon']; $exp = $_POST['exp']; $username = $_POST['username']; $password = $_POST['password']; $user = "root"; $pass = "##########"; $db = "#########"; $table = "#########"; $link = mysql_connect( "localhost", $user, $pass ); if ( ! $link ) { die( "Couldn't connect to the MySQL Server: ".mysql_error() ); } mysql_select_db( $db ) or die ( "Couldn't open $db: ".mysql_error() ); $query = "INSERT INTO staff( fname, lname, email, positon, exp, username, password ) values( $fname, $lname, $email, $positon, $exp, $username, $password )"; mysql_query( $query, $link ) or die ( "INSERT error: ".mysql_error() ); mysql_close( $link ); ?> Link to comment https://forums.phpfreaks.com/topic/82097-solved-another-sql-syntax-error/ Share on other sites More sharing options...
revraz Posted December 17, 2007 Share Posted December 17, 2007 You need single quotes around all your variables. Link to comment https://forums.phpfreaks.com/topic/82097-solved-another-sql-syntax-error/#findComment-417175 Share on other sites More sharing options...
andrew6607 Posted December 17, 2007 Author Share Posted December 17, 2007 Thanks ALOT! Link to comment https://forums.phpfreaks.com/topic/82097-solved-another-sql-syntax-error/#findComment-417182 Share on other sites More sharing options...
rlindauer Posted December 17, 2007 Share Posted December 17, 2007 You also want to properly escape them as well. Look up mysql_real_escape_string() Link to comment https://forums.phpfreaks.com/topic/82097-solved-another-sql-syntax-error/#findComment-417188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.