Jump to content

index and sql query issue


sreddick

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.