-1

I'm getting this error the error(title) on such a simple query:

function getBranch($BranchID){
$query = "SELECT Branch FROM Branches WHERE BranchID = {$BranchID}";
$r = mysql_query($query);
if (!$r) echo "Failed Query: " . mysql_error();
  else return mysql_result($r, 0);
}

I know the mysql_ functions are being deprecated and I know the Column 'Branches' does exist. The var $BranchID is 'AG' when called and I've checked, that is a valid value.

j0k
  • 22,600
  • 28
  • 79
  • 90

1 Answers1

1

You should not be using the deprecated mysql_* functions. It's much better to use PDO and parameterized queries.

The specific problem with your query is that you are missing quotes around your string value:

$query = "SELECT Branch FROM Branches WHERE BranchID = '$BranchID'";

You should also ensure that you escape the value correctly with mysql_real_escape_string.

$query = "SELECT Branch FROM Branches WHERE BranchID = '" . 
          mysql_real_escape_string($BranchID) . "'";

Related

Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452