I'm trying to pull data from my databases into a html table, everything worked fine until I tried introducing another database to add another variable to the table.
here is my code(just for context):
<?php
require 'dbh-inc.php';
$id = $_SESSION['userId'];
if(isset($id) == false)
{
header("Location:../account.php?faliure");
exit();
}
$sql = "SELECT product, productAmount, dateOfPurchase, productStatus, userAddress FROM sales;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0){
while($row = mysqli_fetch_assoc($result)){
$sql1 = "SELECT eLink FROM products WHERE $row\['product'\];";
$result1 = mysqli_query($conn, $sql1);
$resultCheck1 = mysqli_num_rows($result1);
if($resultCheck1 == 0){
$row1['eLink'] = " ";
}
else
$row1['eLink'] = mysqli_fetch_assoc($result1);
echo "<tr><td>". $row['product'] ."</td><td>" . $row['productAmount']. "</td><td>". $row['dateOfPurchase']. "</td><td>". $row['userAddress']. "</td><td>". $row1['eLink'] . "</td><td>" .$row['productStatus']. "</td></tr>" ;
}
}
else
echo '<div>no product purcheses yet</div>';
exit();
?>
the problematic lines are:
$sql1 = "SELECT eLink FROM products WHERE $row\['product'\];";
$result1 = mysqli_query($conn, $sql1);
$resultCheck1 = mysqli_num_rows($result1);
if($resultCheck1 == 0){
$row1['eLink'] = " ";
}
else
$row1['eLink'] = mysqli_fetch_assoc($result1);
the errors I get are:
Notice: Array to string conversion in C:\xampp\htdocs\coupleslove php\includes\manage_sales-inc.php on line 20
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\coupleslove php\includes\manage_sales-inc.php on line 22
Notice: Array to string conversion in C:\xampp\htdocs\coupleslove php\includes\manage_sales-inc.php on line 20
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\coupleslove php\includes\manage_sales-inc.php on line 22
What is wrong with the code? I understand that it has to do with inserting a wrong type to a function, although a couple lines before I do the same and everything is fine, I'm kind of confuzed with what is wrong with the code. is this a syntax problem?
thank you in advance!