Reputation: 27
i have a form named search.php that searches for a database column order_niv
i want to get the values of other columns in the row i searched for if the result is found. i did this
$res = mysqli_query($connz,"SELECT * FROM add_courier WHERE
add_courier.
id= 1");
but it only displays a fixed id even if i didn't search for the row.
from the image below. if i searched for AWB567890 i want to get the values of postal, email, phone etc in the circled only.
here is my search.php
<form class="form-inline justify-content-center my-5 subsribe-rounded" action="result.php" method="post">
<div class="form-group">
<input type="text" name="order_inv" class="form-control px-4 u-rounded-50 u-h-55" placeholder="shipping number Ej:(AWB-100000001)" required>
</div>
<button type="submit" name="submit" class="btn btn-rounded btn-primary u-h-55">
Search Tracking
</button>
</form>
and the result.php
$res = mysqli_query($connz,"SELECT * FROM add_courier WHERE `add_courier`.`id` = 1");
while($row=mysqli_fetch_array($res)){
$tracking = $row['tracking'];
$s_name = $row['s_name'];
$phone = $row['phone'];
$address = $row['address'];
$_SESSION['id'] = $row['id'];
}
Upvotes: 1
Views: 133
Reputation: 304
Maybe the result is not showing cuz you're confusing fetch_array with fetch_assoc.
With fetch_array you use numeric index for the results
$row = mysqli_fetch_array($res);
$res1 = $row[0];
With fetch_assoc you use column_name as the index for the results
$row = mysqli_fetch_assoc($res);
$res1 = $row['id'];
So your code in result.php has to be
$res = mysqli_query($connz,"SELECT * FROM add_courier WHERE `add_courier`.`id` = 1");
while($row=mysqli_fetch_assoc($res)){
$tracking = $row['tracking'];
$s_name = $row['s_name'];
$phone = $row['phone'];
$address = $row['address'];
$_SESSION['id'] = $row['id'];
}
Otherwise, try to print your query result to know if mysql is not returning it, or it has to be with your php usage
var_dump($res);
or
print_r($res);
Upvotes: 1