Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- A simple IF condition.
September 2, 2005, 12:46 pm
rate this thread
a search actually exists in the database.
The form search produces $townsearch
The check should return "Cannot Find The Town" if $townsearch does not
correspond to a recognised townname in the database.
The database is correct, and the SQL query OK.
So why can I type anything in and it accepts it??
(Day 4 of learning PHP)
<?php $townsearch = $_GET['town']; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" name="town" size="20" value="<?php echo $townsearch;
<input type="submit" value="GO" />
$check = @mysql_query ("SELECT townname FROM site01_towns WHERE
echo '<p>Cannot Find The Town</p>';
- Alvaro G Vicario
September 2, 2005, 12:49 pm
Re: A simple IF condition.
Let's check mysql_query() manual page:
"Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns
a resource identifier or FALSE if the query was not executed correctly.
[...] A non-FALSE return value means that the query was legal and could be
executed by the server. It does not indicate anything about the number of
rows affected or returned. It is perfectly possible for a query to succeed
but affect no rows or return no rows."
Your if condition will only be FALSE if you have a syntax error in your SQL
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group