Forum Moderators: coopster

Message Too Old, No Replies

Search database and redirect if true or fail if no match

         

dj1274

7:02 pm on Jan 22, 2005 (gmt 0)



Hi All, i hope someone can help.

I am very new to PHP and am looking for a solution for the following:

I have a database of UK postcodes. If a user enters a matching postcode into a text field on a HTML or PHP page then they get taken to a "success page" where as if they enter a postcode not in the database then they get a "fail page"

I have a rough idea how to connect the database and search via "SELECT * FROM ... etc" but after this i am sadly lacking in knowledge

any help would be greatly accepted.

Thanks

HughMungus

7:18 pm on Jan 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There might be some way to indicate a null result set but I don't know how to do that yet. What I'd do is something like:

if ($result <> "")
{
DO THIS IF THERE IS A RESULT MATCHING THE POST CODE
}
else if ($result == "")
{
DO THIS IF THERE ARE NO RESULSTS MATCHING THE POST CODE
}

...where $result is any field retrieved with your "WHERE postcode = '$enteredpostcode'" sql statement.

mcibor

10:36 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Null result is done by

$number = mysql_num_rows($result);

The variable $result is true if a question is successful, that means that there were no errors on query execution. If there are no rows to return there's no error, just no rows.

Otherwise, the code above is correct

Best regards
Michal Cibor