sreddick Posted December 6, 2009 Share Posted December 6, 2009 I want my code to be able to submit a make and model car, then search the database and print the car the user is looking for. However when you submit any car, all cars are printed. Also having an index error. Can some one tell me what's wrong. HTML code <html> <body> <form action=searchcars.php method=GET> Look For: <p> Make: <input type="text" name="make" size=25 maxlength=25> <p> Model: <input type="text" name="model" size=25 maxlength=25> <p> <input type="submit" value="Search for Car"> </form> </body> </html> PHP code <html> <body> <?php mysql_connect ('localhost', 'root', 'reddick1'); mysql_select_db ('sdrcars'); if ($make == "") {$make = '%';} if ($model == "") {$model = '%';} $query = ("SELECT * FROM cars WHERE make LIKE '$make%' AND model '$model%'"); $result = mysql_query ($query); if ($row = mysql_fetch_array($result)) { do { print $row["year"]; print (" "); print $row["make"]; print (" "); print $row["model"]; print (" "); print $row["bodystyle"]; print (" "); print $row["price"]; print (" "); print $row["description"]; print ("<p>"); } while($row = mysql_fetch_array($result)); } else {print "Sorry, that car is not available";} ?> </body> </html> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/184187-index-and-sql-query-issue/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.