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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.