View Single Post
Old 08-02-2021, 12:42 PM  
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Ive edited the code as suggested for both pages and now its throwing out a blank page with the 'ID' and 'Title' table but no data being inserted, i checked the error logs and its showing me this:

Quote:
[02-Aug-2021 14:30:31 America/Chicago] PHP Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /home2/blah/blah.com/index.php on line 6
[02-Aug-2021 14:30:31 America/Chicago] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in /home2/blah/blah.com/index.php on line 26
Here is the new code im using based on the feedback in this thread so far...

index.php

PHP Code:
<?php


// change the user_name and password
$con mysqli_connect("localhost""dbuser""dbpass");
mysqli_select_db("dbname",$con);
 

$id $_GET['RecipeID'];

// Check connection
if (mysqli_connect_errno()) {
  echo 
"Failed to connect to MySQL: " mysqli_connect_error();
  exit();
}

$result mysqli_query($con,"SELECT RecipeID, Title FROM Recipes WHERE id = $id");

echo 
"<table width=100%>
<tr>
<th>ID</th>
<th>Title</th>
</tr>"
;


while(
$row mysqli_fetch_array($result))
{

$id $row['RecipeID'];

echo 
"<tr>";
echo 
"<td>" $row['RecipeID'] . "</td>";
echo 
"<td> <a href='viewmore.php?id=$id'>" $row['Title'] . "</a> </td>";
echo 
"</tr>";
}
echo 
"</table>";

?>
and for the viewmore.php

PHP Code:
<?php

// change the user_name and password
$con mysqli_connect("localhost""dbuser""dbpass");
mysqli_select_db("dbname",$con);
 
$id $_GET['RecipeID'];

// Check connection
if (mysqli_connect_errno()) {
  echo 
"Failed to connect to MySQL: " mysqli_connect_error();
  exit();
}

$result mysqli_query($con,"SELECT RecipeID, Title FROM Recipes WHERE id = $id");

echo 
"<table width=100%>
<tr>
<th>ID</th>
<th>Title</th>
</tr>"
;


while(
$row mysqli_fetch_array($result))
{

$id $row['RecipeID'];

echo 
"<tr>";
echo 
"<td>" $row['RecipeID'] . "</td>";
echo 
"<td> <a href='viewmore.php?id=$id'>" $row['Title'] . "</a> </td>";
echo 
"</tr>";
}
echo 
"</table>";

?>
The page itself isn't throwing out any errors from the connection, and the ID and Title shows in the table but no data is being displayed.

The url im using is:

domain.com/index.php?id=X (where X is a valid RecipeID in the table)
domain.com/viewmore.php?id=X (where X is a valid RecipeID in the table)

I'm going to get a few hours sleep, but if ya'll happen to spot anything amiss it'd be appreciated.

Thanks again for the help so far
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote