lAZLf Posted December 28, 2009 Share Posted December 28, 2009 I'm creating a registration page for my website. I have two forms I want to check the value of to see if it is in the database already (username and email). How could I do this? Quote Link to comment Share on other sites More sharing options...
cags Posted December 28, 2009 Share Posted December 28, 2009 There are several ways, the most common method is probably to use "SELECT id FROM table WHERE username='$username'" and to then use mysql_num_rows to check how many rows are returned. If it's 0 then you know that the username passed as $username is not in the database already. Quote Link to comment Share on other sites More sharing options...
lAZLf Posted December 28, 2009 Author Share Posted December 28, 2009 I did what u suggested, but it won't work for some reason. Â I keep getting this error: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home4/annarbo1/public_html/registerin.php on line 12 Your passwords or email adresss don't match up" Â the code: <?php session_start(); $con = mysql_connect("localhost","xxxxxxx","xxxxxxxxx"); if (!$con) Â { Â die('Could not connect: ' . mysql_error()); Â } mysql_select_db("annarbo1_Archive", $con); $date = date("Y/m/d"); $sql="INSERT INTO people (fname, lname, username, password, joined, email, level) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[user]',sha1('$_POST[pass]'),'$date','$_POST[email]','norm')"; $sqlcheck="SELECT * FROM people WHERE username = '$_POST[user]' OR email = '$_POST[email]'"; $numrows = mysql_num_rows($sqlcheck); if (!empty($_POST['pass']) || !empty($_POST['user']) || !empty($_POST['confemail']) || !empty($_POST['confpass']) || !empty($_POST['email']) || !empty($_POST['fname']) || !empty($_POST['lname'])) { if($_POST['confemail'] == $_POST['email'] && $_POST['pass'] == $_POST['confpass']) { if($numrows == 0) { if (!mysql_query($sql,$con)) Â { Â die('Error: ' . mysql_error()); Â } else{ header ("Location: userinfo.php"); } } else { echo "username or email taken already"; } } else { echo"Your passwords or email adresss don't match up"; } } else { echo "empty fields"; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
atl_andy Posted December 28, 2009 Share Posted December 28, 2009 You have syntax issues...try: $sql="INSERT INTO people (fname, lname, username, password, joined, email, level) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[user]',sha1('$_POST[pass]'),'$date','$_POST[email]','norm')"; $result = mysql_query($sql); $sqlcheck="SELECT * FROM people WHERE username = '$_POST[user]' OR email = '$_POST[email]'"; $result = mysql_query($sqlcheck); $numrows = mysql_num_rows($result);  check these links for the correct usage of INSERT and SELECT statements  http://us.php.net/mysql_num_rows for using mysql_num_rows  and http://us.php.net/manual/en/function.mysql-query.php for SELECT and INSERT statements   Quote Link to comment Share on other sites More sharing options...
lAZLf Posted December 28, 2009 Author Share Posted December 28, 2009 ^thanks! it's working now Quote Link to comment Share on other sites More sharing options...
atl_andy Posted December 28, 2009 Share Posted December 28, 2009 Please mark this topic solved. Quote Link to comment Share on other sites More sharing options...
lAZLf Posted December 28, 2009 Author Share Posted December 28, 2009 how do i do that? Quote Link to comment Share on other sites More sharing options...
atl_andy Posted December 28, 2009 Share Posted December 28, 2009 There should be a green button near the bottom of your screen that says "SOLVED", or something...click it. Quote Link to comment Share on other sites More sharing options...
lAZLf Posted December 28, 2009 Author Share Posted December 28, 2009 ah thanks Quote Link to comment 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.