mysql query help

Im trying to write a query to verify that a given user id and email address are indeed associated with each other. I have succeeded as long as the user id IS in the database. Im having trouble when the given user id is not a valid user id. When the form is submitted and the user id is not in the database, the browser is going to a blank screen. code is below…
[php]

$userid = $_POST[‘nar’];
$email = $_POST[‘mail’];

$con = mysql_connect(“localhost”, “some_db”, “password”);
mysql_select_db($database) or die( “Unable to select database”);
$result = mysql_query(“SELECT * FROM table
WHERE uid=’$userid’”);

   while($row = mysql_fetch_array($result)){
   IF ($row['mail']==$email && $row['narid']==$narid){
   header('Location: http://www.webpage.com/=verified');
   } else {
   header('Location: http://www.webpage.com/=not_verified');
   }

}

mysql_close();[/php]

any help would be greatly appreciated, im pulling my hair out.

need to do some validation on the id before its submitted then. look up preg_match and the patterns, you’ll want to use that to make sure the format for the user id is proper. If you do it before the query, then you can return an error message and not have to worry about the user id not being proper.

Hi, Im Greg. I started this thread and wanted to explain better.

The format doesn’t seem to the problem(I don’t think). Right now if they submit userid: 123456 and email: [email protected] for example and there is no userid:123456 the page just stops blank on the .php page. I want them directed to the same page they would go to if userid:123456 was in the system but [email protected] was not the correct email address. I dont know if thats any clearer …

[php]
$con = mysql_connect(“localhost”, “some_db”, “password”);
mysql_select_db($database) or die( “Unable to select database”);

$userid = $_POST[‘nar’];
$email = $_POST[‘mail’];

$find_email = mysql_query(“SELECT mail FROM table WHERE mail =’$email’”);
$find_id = mysql_query(“SELECT uid FROM table WHERE uid=’$userid’”);

if(mysql_num_rows($find_email) == 0) {
header(‘Location: http://www.webpage.com/=not_verified’);
} else {
header(‘Location: http://www.webpage.com/=verified’);
}

if(mysql_num_rows($find_id) == 0) {
header(‘Location: http://www.webpage.com/=not_verified’);
} else {
header(‘Location: http://www.webpage.com/=verified’);
}

mysql_close();[/php]

That’s a quick and easy way of testing for both.

Thank you. Its works :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service