netman182 Posted December 2, 2009 Share Posted December 2, 2009 i am having problems with this. i can't seem to figure it out. I am getting this error: You have an error in your SQL syntax phpmyadmin server version: Server version: 5.1.37 PHP version: 5.3 here is the code. can anyone help? it is probably a simple problem. ID is an auto increment field. the rest are text <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="95887rj"; // Mysql password $db_name="bccsl"; // Database name $tbl_name="managers2"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="INSERT INTO Managers2 (ID, First, Last, City, Address, Postal, Home, Cell, Email, Username, Password, Church, Team) VALUES ('',$_POST[firstname]','$_POST[lastname]','$_POST[city]','$_POST[address]','$_POST[postal]','$_POST[home]','$_POST[cell]','$_POST[church]','$_POST[team]','$_POST[username]','$_POST[password]')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/ Share on other sites More sharing options...
mikesta707 Posted December 2, 2009 Share Posted December 2, 2009 first thing here '',$_POST[firstname]' you have an unmatched single quote '','$_POST[firstname]' also you need to surround your array variables with curly brackets, IE '','{$_POST[firstname]}' Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/#findComment-969527 Share on other sites More sharing options...
netman182 Posted December 2, 2009 Author Share Posted December 2, 2009 ok i changed the first single qoute and added the {} to the rest. now i get this: Parse error: syntax error, unexpected '}', expecting ']' Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/#findComment-969536 Share on other sites More sharing options...
rajivgonsalves Posted December 2, 2009 Share Posted December 2, 2009 to avoid confusion in the query I would suggest this $sql = sprintf("INSERT INTO Managers2 (First, Last, City, Address, Postal, Home, Cell, Email, Username, Password, Church, Team) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", $_POST['firstname'],$_POST['lastname'],$_POST['city'],$_POST['address'],$_POST['postal'],$_POST['home'],$_POST['cell'],$_POST['church'],$_POST['team'],$_POST['username'],$_POST['password']); Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/#findComment-969544 Share on other sites More sharing options...
netman182 Posted December 2, 2009 Author Share Posted December 2, 2009 now i am getting this error: Error: Column count doesn't match value count at row 1 Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/#findComment-969549 Share on other sites More sharing options...
Gayner Posted December 2, 2009 Share Posted December 2, 2009 now i am getting this error: Error: Column count doesn't match value count at row 1 Hey google some questions before posting here, because u can get faster responses :-) That error means u don't have matching rows in ur inserts check again. Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/#findComment-969552 Share on other sites More sharing options...
netman182 Posted December 2, 2009 Author Share Posted December 2, 2009 thanks gayner for being captian dumbass. solved it by a PM. thanks to all who helped. Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/#findComment-969553 Share on other sites More sharing options...
Gayner Posted December 2, 2009 Share Posted December 2, 2009 thanks gayner for being captian dumbass. solved it by a PM. thanks to all who helped. Your the Captain dumbass for spelling "Captian" wrong :-) Solved by PM? no1 want's to help thru pm's post in forum please, thx Link to comment https://forums.phpfreaks.com/topic/183687-syntax-error-argh-i-will-shoot-this-thing/#findComment-969554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.