So a few weeks ago I was told I had covid, so after 3 weeks of pure hell, sleeping non-stop, vomiting, aches and pains plus coughing, I finally get the all clear and am back at it.
No clue how I even got it as I have pretty much remained a hermit this whole time.
Anyway, I'm trying to get caught up on some of my personal projects, including a little recipe site that I'm having an issue with... I'm using the following code on an index page for a website..
PHP Code:
<?php
$con=mysqli_connect("localhost","recipes","password","recipelist");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Recipes");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Title</th>
<th>Method</th>
<th>Ingredients</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$link = "recipes.php?id=".$row['RecipeID'];
echo "<tr>";
echo "<td><a href = ". $link . ">" . $row['Title'] . "</a></td>";
echo "<td>" . $row['Ingredients'] . "</td>";
echo "<td>" . $row['Method'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Which does everything that it is supposed to for that page (for now).
However, when the link that is generated is clicked on to go to recipes.php?id=4 it keeps telling me the page isnt working.
This is the code im using in the recipes.php page, can anyone give me a little guidance as to what is messed up please?
PHP Code:
<?php
// check incoming params exist
if ( ! isset($_GET['id'] ) {
// missing param, go to an error page for example
header('Location: index.php');
exit;
}
// You can now use $_GET['id'] which will be the id number passed
// any way you want.
// For example using a PDO connection called $pdo
$table = "Recipes";
$sql = "SELECT * FROM $table WHERE id = :RecipeID";
try {
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
$stmt->execute();
$rows = $stmt->FetchAll(); // $rows now contains all the results of the query
}
catch( PDOException $e) {
echo $e-getMessage();
}
foreach ( $rows as $row ) {
// do things with the $row['column_name'] data
}
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td>" . $row['Ingredients'] . "</td>";
echo "<td>" . $row['Method'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
Its basically not showing anything.
What it *should* be doing is displaying a table of all the data for the MYSQL database recordwith a RecipeID of 4 on that recipes.php page.
Any help would be greatly appreciated.
Oh and to top the last 3 weeks of dealing with covid off... New Orleans is now expecting to be hit by a cat 4 hurricane and parts of the area have been issued a mandatory evacuation, thankfully I'm in an area where its only voluntary and well inside the levee protection system
