Jump to content

Trouble checking if a name already exists


coolgamer48

Recommended Posts

Hey, so I'm making this registration page for a site (it's not really registering a user, but it's like the same thing). I actually have a sign in page with simmilar code that works fine. But for some reason it won't work when I'm doing it now. Can anyone find a problem with this code:

		$sql = "CREATE TABLE kingdoms
	(
		name varchar(15),
		PRIMARY KEY(name),
		date_est date(),
		acreage int(1000),
		money int(20),
		user varchar(15)
	)";
	if (mysql_query($sql,$con) == false)
	{
		echo("We're sorry, there was an error with the Kingdom database.");
	}
	$sql = "SELECT * FROM kingdoms WHERE name=\"".mysql_real_escape_string($_POST["kingdom_name"])."\"";
	$kingdoms_list = mysql_query($sql,$con);
	if (mysql_num_rows($kingdoms_list) > 0)
	{
		echo "Sorry, that Kingdom name is already in use. You can<br />
			<ul>
				<li>Try a different name if you have something in mind</li>
				<li>Consider something like ".$_POST["kingdom_name"]." of ".$_COOKIE["username"]."</li>
			</ul>";
	}

 

I'm pretty sure the problem is with creating the table, but I'm not sure. Please and thank you!

Could put a Else statement here

 

if (mysql_query($sql,$con) == false)

{

echo("We're sorry, there was an error with the Kingdom database.");

}

else {

//then do your code

 

The way you have it, if there is an errror, the rest of your code still executes.

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.