WHERE/AND problem in query to MySQL
| From: | Knut Lekvam | Date: | Tue, 12 Sep 2000 10:18:20 +0000 |
| Subject: | WHERE/AND problem in query to MySQL | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-2823@lists.php.net to get a copy of this message | ||
I have the following problem as I am trying to set up a php script to search in a mysql database.
But my wher/and query fails.
I have a table called adresse, with the following first record:
+----+-----------+----------------+--------+------+
| id | kommune | gate | gatenr | leil |
+----+-----------+----------------+--------+------+
| 1 | Stavanger | Kannikgata | 21 | A9 |
Everything is connecting fine and I have fed in the following 4 variables
through a form:
$kom, $gt, $gnr, $le
I have included the following code section in a page:
echo "from forms:\n<br><br>";
echo "You have searched for ",$gt," \n";
echo $gnr,"\n";
echo ", appartment no. ",$le,"\n<br>";
echo "which is sited in ",$kom,".\n<br><br>";
$result = mysql_query("SELECT * FROM adresse WHERE (gatenr=$gnr)",$db);
$myrow = mysql_fetch_array($result);
echo "from db:\n<br><br>";
echo "gatenr: \n";
echo $myrow["gatenr"],"\n<br>";
echo "id: \n";
echo $myrow["id"],"\n<br><br>;
It gave this output in my browser:
from forms:
You have searched for Kannikgata 21 , appartment no. A9
which is sited in Stavanger.
from db:
gatenr: 21
id: 1
...so far so good. But if I add more records in my table I need to be more
spesific. I wanted to search for the entire form input with the following
expression:
$result = mysql_query("SELECT * FROM adresse WHERE (kommune=$kom AND gate=$gt AND gatenr=$gnr
AND leil=$le)",$db);
(Then afterwards I wanted to use the recovered ID for search in another table)
But the output was:
from forms:
You have searched for Kannikgata 21 , appartment no. A9
which is sited in Stavanger.
Warning: 0 is not a MySQL result index in /home/httpd/html/script/side2g.php3 on line 42
from db:
gatenr:
id:
I dont understand why the latter query failed?
--
Knut Lekvam
__________________________________________________________________
Denne eposten er sendt ved hjelp av http://www.Organizer.net
- Norges ledende webbaserte kommunikasjonsløsning.