I need to display a table that shows the user that in-putted the joke into the database. I have a table for the jokes names 'joke' and a table for the user named 'author' joke table has id, joketext, jokedate, authorid author table has id, name, email so the 'authorid' is the same as the 'id' in author table.
<?php
$con=mysqli_connect("localhost","user","password","ijdb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysql_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
ON authorid = author.id");
echo "<form action='delete1.php' method='post'>
<table border='1'>
<tr>
<th>Joke</th>
<th>Date</th>
<th>Name</th>
<th>Email</th>
<th>Delete</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['joketext'] . "</td>";
echo "<td>" . $row['jokedate'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td><input type='submit' name='deleteItem' value='".$row['id']."' /></td>";
echo "</tr>";
}
echo "</table>";
echo "</form></br>";
mysqli_close($con);
?>
I get this error Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\kimmy\jokes\joke1.php on line 22 and an empty table
Thanks
It should be:
$result = mysqli_query($con, "SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
ON authorid = author.id");
You can't use mysql_query()
when you're using the mysqli
extension.
Error is you are using mysql_query instead of mysqli_query
so the code becomes
<?php
$con=mysqli_connect("localhost","user","password","ijdb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
ON authorid = author.id");
echo "<form action='delete1.php' method='post'>
<table border='1'>
<tr>
<th>Joke</th>
<th>Date</th>
<th>Name</th>
<th>Email</th>
<th>Delete</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['joketext'] . "</td>";
echo "<td>" . $row['jokedate'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td><input type='submit' name='deleteItem' value='".$row['id']."' /></td>";
echo "</tr>";
}
echo "</table>";
echo "</form></br>";
mysqli_close($con);
?>
Try changing the following
$result = mysql_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
ON authorid = author.id");
to
$result = mysqli_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
ON authorid = author.id");
You are using mysql_query instead of mysqli_query