Code not returning results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Code not returning results

Post by PastorHank »

I have placed the following code in my program. The purpose of the query is to find out if a serial number exists in the database. if it doesn't exist I need the program to go to a 'sorry page' - when I enter data into the setup form, the script seems to run by this code and go to the next section which checks if the user id is in another table - that section of code works

Code: Select all

/*this comes from the data entry form

$user_sn=strip_tags(trim($_POST['registration_id']));

/* Lets check to see if we have a valid serial number

/* I've tried formatting the query in several different ways

$query=sprintf("SELECT * FROM serial_numbers WHERE sd='$user_sn'" '
		mysql_real_escape_string($user_sn));

$result=mysql_query($query);
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
    }else{
    $num=mysql_num_rows($result);
	echo $num;
	die();
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row['sd'];
    echo $row['fn'];
}
/* at this point I want the program to go and tell the user there's no serial number on record

if ($num < 1){
			header("Location:http://www.domain.com/sub-folder/bad_serial.html");
			exit();
			}

// Free the resources associated with the result set
mysql_free_result($result);
The program seems to run right past that segment of code and then comes to this - which works

Code: Select all


/* Lets see if this login is in the database and if not then let's go ahead and create the user database */
$query="SELECT user_id FROM users WHERE user_id='$new_user'";
$result=mysql_query($query);

$num=mysql_num_rows($result);

if ($num == 1){
			header("Location:http://www.domain.com/sub-folder/usersetup.html");
			exit();
			}
			else
			{
	/*query to insert new record into table
		    }	
Any ideas are greatly appreciated, thanks
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Re: Code not returning results

Post by PastorHank »

Found it - By posting the code here I noticed that I had left off the ending of a comment line - replaced it and things worked - just goes to show you it's the little things that both make you :banghead: and then :D
Post Reply