简体   繁体   中英

What am I doing wrong with his php mysql

What my intention is to put a table on my website containg some fields from a datbase which contain an ID

$con = mysqli_connect('hostname','username','password','dbname');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}



$sql="SELECT * FROM Orders WHERE `Student UID` = '".$id."'";
$result = mysqli_query($con,$sql);
echo 
echo "<table><tr><th>Product</th><th>Cost</th></tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['MenuItemName'] . "</td>";
    echo "<td>" . $row['Price'] . "</td>";


    echo "</tr>";
}
echo "</table>";

At the moment when I am running this, I am jut getting a table like this

+---------+-------+
| Product | Price |
+---------+-------+

My database looks like this

+--------------+-------+-------------+
| MenuItemName | Price | Student UID |
+--------------+-------+-------------+
| Foo          |    99 |       12345 |
| Foo2         |    11 |       11111 |
| Foo2         |    11 |       12345 |
+--------------+-------+-------------+

What am I doing wrong with this?

Try changing this line:

$sql="SELECT * FROM Orders WHERE 'Student UID' = '".$id."'";

to:

$sql="SELECT * FROM Orders WHERE `Student UID` = '".$id."'";

Shout solve your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM