Jump to content

Check if something exists in the database already


lAZLf

Recommended Posts

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);
?>

Link to comment
Share on other sites

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

 

 

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.