Akenatehm Posted November 23, 2008 Share Posted November 23, 2008 Hey Guys, I am trying to insert data into a MySQL table, it is showing one of the if error messages ("Could not insert comment") Any help would be greatly appreciated. Here is my code: <?php include "connect.php"; if(isset($_POST['submit'])) { $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; if(strlen($username)<1) { print "You did not enter a username."; } else if(strlen($password)<1) { print "You did not enter a password."; } else { $insert="Insert into users (username,password,email) values('$username','$password','$email')"; mysql_query($insert) or die("Could not insert comment"); print "Comment added. <A href='display.php'>Click here</a> to see all comments."; } } ?> Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/ Share on other sites More sharing options...
samona Posted November 23, 2008 Share Posted November 23, 2008 what does the connect.php file look like? Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/#findComment-696640 Share on other sites More sharing options...
Akenatehm Posted November 23, 2008 Author Share Posted November 23, 2008 As far as I know it is connecting because it wasn't before and now it's not showing those errors. Anyway here it is: <?PHP $db = mysql_connect ("localhost", "username", "password"); if (!$db) die ("No Database Found"); if (!mysql_select_db ("kaurlcom_messenger",$db)) die("No Database Selected"); ?> Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/#findComment-696642 Share on other sites More sharing options...
samona Posted November 23, 2008 Share Posted November 23, 2008 Can you insert hte mysql_error() function into your program where you have the insert query and post the output. mysql_query($insert) or die("Could not insert comment" . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/#findComment-696644 Share on other sites More sharing options...
Akenatehm Posted November 23, 2008 Author Share Posted November 23, 2008 Ok. Could not insert commentUnknown column 'password' in 'field list' Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/#findComment-696647 Share on other sites More sharing options...
samona Posted November 23, 2008 Share Posted November 23, 2008 You have to type the column names in the program exactly as they are in the Table. It is case sensitive. Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/#findComment-696649 Share on other sites More sharing options...
Akenatehm Posted November 23, 2008 Author Share Posted November 23, 2008 Omg such a stupid mistake, put password instead of pass. Ugh! Thanks once again for all your help! Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/#findComment-696652 Share on other sites More sharing options...
samona Posted November 23, 2008 Share Posted November 23, 2008 my pleasure Link to comment https://forums.phpfreaks.com/topic/133847-solved-problem-inserting-data-into-sql-table/#findComment-696663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.