twinytwo Posted December 6, 2011 Share Posted December 6, 2011 Hi guys Im looking to save the contents of 4 textboxes to a mySql db. Using wamp, phpmyadmin etc. ?php $Name = $_Post('Name'); $Age = $_Post('Age'); $Sex = $_Post('Sex'); $Address_1 = $_Post('Address_1'); mysql_connect("127.0.0.1","user","") or die ('Error: ' .mysql_error()); mysql_select_db("user"); $query ="INSERT INTO users(Name,Age,Sex,Address_1) VALUES('".$Name."', '".$Age."','".$Sex."','".$Address_1."'); mysql_query($query) or die ('Error updating datadase'); mysql_Close(); ?> This is the code im using, it dosent seem to do anything to the database..... can someone point out where im going wrong... thanks Quote Link to comment https://forums.phpfreaks.com/topic/252602-saving-to-a-sql-database-using-php-and-wamp/ Share on other sites More sharing options...
QuickOldCar Posted December 6, 2011 Share Posted December 6, 2011 Post using the code tags <?php $Name = $_POST['Name']; $Age = $_POST['Age']; $Sex = $_POST['Sex']; $Address_1 = $_POST['Address_1']; mysql_connect("127.0.0.1","user","password") or die ('Error: ' .mysql_error()); mysql_select_db("user"); $query ="INSERT INTO users(Name,Age,Sex,Address_1) VALUES('$Name', $Age','$Sex','$Address_1')"; mysql_query($query) or die ('Error updating datadase'); mysql_close(); ?> Missed the POST and also the square brackets, must be a little tired Should the POST values be uppercased? Quote Link to comment https://forums.phpfreaks.com/topic/252602-saving-to-a-sql-database-using-php-and-wamp/#findComment-1295029 Share on other sites More sharing options...
gizmola Posted December 6, 2011 Share Posted December 6, 2011 Did you look in your error log? Your code has several obvious syntax errors. The syntax for accessing arrays is to use [] not (). Also $_POST is the name of the superglobal array... all caps. $Name = $_POST['Name']; Also, php supports interpolation when you use double quotes. The values of variables will be inserted into the string, so your code will be alot easier to read if you utilize it rather than concatenation. $query ="INSERT INTO users (Name, Age, Sex, Address_1) VALUES ('$Name', '$Age', '$Sex', '$Address_1')"; What database type is the Age column? If it's not a string you would not include the single quotes around it in the values section of the query. Quote Link to comment https://forums.phpfreaks.com/topic/252602-saving-to-a-sql-database-using-php-and-wamp/#findComment-1295030 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.