-1

When I use "55555555555555555" it returns the values, when I use "A5555555555555555" I get Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\bidTobuy2.php on line 35 []

<?php
$VIN = "A5555555555555555";

$result = mysql_query("SELECT VIN, Bid, BoughtFrom, Mileage from tblevaluated WHERE VIN     = $VIN");



  $json_response = array();
  ////line 35: 
  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
  $row_array['BoughtFrom'] = $row['BoughtFrom'];
  $row_array['Bid'] = $row['Bid'];   
  $row_array['miles'] = $row['Mileage']; 


    array_push($json_response,$row_array);

}

echo json_encode($json_response);

?>

Glenn
  • 79
  • 10
  • 6
    Because strings need to be quoted in SQL statements, same as you quote a string value in PHP – Mark Baker Dec 29 '14 at 19:01
  • 5
    Now stop using the old, deprecated MySQL extension, and start using MySQLi or PDO with prepared statements/bind variables – Mark Baker Dec 29 '14 at 19:02
  • PDO is my next class, unfortunately the current course I'm in the middle of is old php. Thanks for the help, works perfectly. Set it as answer so I can give you credit. – Glenn Dec 29 '14 at 19:09

2 Answers2

1

The quotes at the end need to be moved in

$result = mysql_query("SELECT VIN, Bid, BoughtFrom, Mileage from tblevaluated WHERE VIN     = $VIN");

Should be

$sql = "SELECT VIN, Bid, BoughtFrom, Mileage from tblevaluated WHERE VIN  = '" . $VIN . "'";
$result = mysql_query($sql);

Edit: Yeah, as they said, strings definitely need to be wrapped. Updated.

jeroen
  • 90,003
  • 21
  • 112
  • 129
cm-stack
  • 51
  • 4
0

strings vs numbers, man. need to quote them.

$result = mysql_query("SELECT VIN, Bid, BoughtFrom, Mileage from tblevaluated WHERE VIN = '$VIN'");
Todd
  • 5,173
  • 3
  • 27
  • 45