We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
  • 2
Sql row Checking
Topic Started: May 13 2005, 12:16 AM (678 Views)
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
Code:
 

<?

include("config.php");

//connection
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

//database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

//checks for duplicates
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, the username $username is already taken.<br>";
echo "<a href=regbox.php>Try again</a>";
exit;
} else {

// insert
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."')")
or die("Error ".mysql_error());

// print a success message
echo "Thankyou, your membership has been added to the site<br>";
}

?>


This is a code i use to do the same thing, i added a couple of comments to help you, maybe you could see how this one does it.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
I relized it worked, but the redirect I had at the bottom for people that had it worked messed with the error message.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1
  • 2