Jump to content

Not inserting data into table


phpcode

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.