coolgamer48 Posted January 2, 2008 Share Posted January 2, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/84165-trouble-checking-if-a-name-already-exists/ Share on other sites More sharing options...
kts Posted January 2, 2008 Share Posted January 2, 2008 It will error when you try to create, because it already exists, try removing that from your code Quote Link to comment https://forums.phpfreaks.com/topic/84165-trouble-checking-if-a-name-already-exists/#findComment-428437 Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84165-trouble-checking-if-a-name-already-exists/#findComment-428441 Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 This is probably better $tablename="Kingdoms"; $res = mysql_query("show table status like '$tablename'") or die(mysql_error()); $table_exists = mysql_num_rows($res) == 1; Quote Link to comment https://forums.phpfreaks.com/topic/84165-trouble-checking-if-a-name-already-exists/#findComment-428444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.