SELECT * FROM WHERE Query isn't retrieving any results

4k views Asked by At

I'm using a SELECT * FROM "" WHERE "" = "" query and I'm not sure what I'm doing wrong with it. I'm trying to select an item based on its PO which is a completely unique identifier to one row in the table. Here's my process in doing so:

$jobnumber = $_GET['jref'];
$query = "SELECT * FROM `po_10152796` WHERE `po` = " .$jobnumber;
$results = mysqli_query($conn,$query) or die(mysqli_error($conn));
$rowitem = mysqli_fetch_array($results);
    $jobname = $rowitem['Job Name'];
    $phone = $rowitem['phone'];

Things i know are correct:

  • The "jobnumber" is retrieved correctly and matches up with an element in the table
  • The table is named "po_10152796" and there is a column named "po"

enter image description here

2

There are 2 answers

0
AudioBubble On BEST ANSWER

Forgot to post this, redid the code with prepared statements and it works, not sure what exactly I changed but here it is anyhow:

    $jobnumber = $_GET['jref'];
$stmt = $conn->prepare( "SELECT `Job Name`, `Address`, `phone`, `description`, `materials` FROM po_10152796 WHERE po = ?");
$stmt->bind_param("i", $jobnumber);
if($stmt->execute()){
    $stmt->bind_result($jobname, $address, $phone, $description, $materials);
    $stmt->fetch();
}
1
Zakarya Chalnark On

try this line for the query

$query = "SELECT * FROM `po_10152796` WHERE `po` = '" .$jobnumber. "' ";