Re: WHERE/AND problem in query to MySQL

From: Date: Tue, 12 Sep 2000 10:55:57 +0000
Subject: Re: WHERE/AND problem in query to MySQL
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-16326@lists.php.net to get a copy of this message
hi, i'll think you miss to send the complete form and so if theres no value for $gnr or $le then there are no rows in the result. so first of all check if the form submits all the values afterwars check the result of your mysql_query for ..... no rows => new entry in form ..... one (or more rows) => continue andreas 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. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#16326) next »