phpcode Posted March 30, 2008 Share Posted March 30, 2008 This code is meant to insert the users info into the database called accounts but it doesn't and I don't get any errors. $dbhost = 'localhost'; $dbname = 'site'; $dbuser = 'root'; $dbpass = ''; $dbtable = 'accounts'; $db = mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error()); if (!mysql_select_db($dbname)) { exit('<strong>Error: </strong>Couldn\'t select MySQL Database.<br />'.mysql_errno().': '.mysql_error()); } $db = mysql_query("SELECT * FROM $dbtable"); if (@mysql_num_rows($db) != 0) { while ($row = mysql_fetch_array($db)) { if ($username == $row['username']) { $error .= "Username already registered"; } } } $keys = '`username`,`password`,`email`'; $values = "'$username','$password','$email'"; $db = mysql_query("INSERT INTO $dbtable ($keys) VALUES ($values)"); if (!$db) { exit('<strong>Error: </strong>Couldn\'t insert into MySQL Database.<br />'.mysql_errno().': '.mysql_error()); } else { echo "Thanks for registering " . $username . "! An email has been sent to you containing an activation link. You must click it before you can login."; } } Can anyone see anything wrong? Link to comment https://forums.phpfreaks.com/topic/98573-not-inserting-data-into-table/ Share on other sites More sharing options...
mwasif Posted March 30, 2008 Share Posted March 30, 2008 Print the query and execute this in mysql echo "INSERT INTO $dbtable ($keys) VALUES ($values)"; Link to comment https://forums.phpfreaks.com/topic/98573-not-inserting-data-into-table/#findComment-504518 Share on other sites More sharing options...
phpcode Posted March 30, 2008 Author Share Posted March 30, 2008 I got this: INSERT INTO ye (`username`,`password`,`email`) VALUES ('test','testpass','[email protected]') Link to comment https://forums.phpfreaks.com/topic/98573-not-inserting-data-into-table/#findComment-504695 Share on other sites More sharing options...
mwasif Posted March 30, 2008 Share Posted March 30, 2008 Did you run this query in MySQL? Link to comment https://forums.phpfreaks.com/topic/98573-not-inserting-data-into-table/#findComment-504705 Share on other sites More sharing options...
phpcode Posted March 30, 2008 Author Share Posted March 30, 2008 Nope I want it all done in PHP. Link to comment https://forums.phpfreaks.com/topic/98573-not-inserting-data-into-table/#findComment-504708 Share on other sites More sharing options...
mwasif Posted March 30, 2008 Share Posted March 30, 2008 Running this code will tell you whether you have ant syntax error or not. In your application, make sure you are connecting to right database. Link to comment https://forums.phpfreaks.com/topic/98573-not-inserting-data-into-table/#findComment-504724 Share on other sites More sharing options...
fenway Posted March 30, 2008 Share Posted March 30, 2008 Nope I want it all done in PHP. Huh? Link to comment https://forums.phpfreaks.com/topic/98573-not-inserting-data-into-table/#findComment-504839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.