View Single Post
Old 09-06-2021, 06:29 PM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
<?php
//Get rid of the shit you posted today, most of what you needed you already had. It was just in the wrong place

// k33n and sarettah help with code fixes and examples from gfy
// check incoming params exist

if ( ! isset($_GET['id'] ) ) { //1.you were missing a )
// 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
// 2. Do the PDO connection

$pdo = new PDO("mysql:host=localhost;dbname=database", "dbuser","dbpass");
$table = "Recipes";
// Select * pulls all the fields from the table
$sql = "SELECT * FROM $table WHERE ID = :id";
try {
$stmt = $pdo->prepare($sql);

$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
$stmt->execute();
}
catch( PDOException $e) {
echo $e-getMessage(); //<-- You should do a die() here to kill the program
}

//I moved this out of the if, just better style imho

$row=$stmt->fetch(PDO::FETCH_ASSOC);

//Your query will only return one row, the row with id as key, I changed from fetchall to fetch assoc which will give us that one record
$title = $row['RecipeName'];
$description = $row['RecipeDescription'];
$random_tags = $row['Author'];

?>
<!DOCTYPE html>
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<meta charset="UTF-8"/>
<title><?php echo $title; ?> Recipe | Sitename</title>
<meta name="Description" content="<?php echo $description; ?>">
<meta name="Keywords" content="<?php echo $title; ?> Recipe Ingredients Make <?php echo $title; ?> Recipes">
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body class="home page page-id-21 page-template-default ie et_includes_sidebar">
<?php
require('./templates/header.php');
?>
<div id="hd_logo0"><p><a href="http://www.domain.com">
<img class="alignnone size-full wp-image-169" alt="" src="logo.png" style="width: 310px"/></a></p>
</div>
</div> //<-----------------------------------------------What is this closing. Where is container opened?
<!-- end .container -->

<?php //in middle:
require('./templates/secondary.php');
?>

included in secondary.php is a search function too, do you need to see the code for that? //<---NO

<center><div id="main-area">
<div class="container" style="left: 0px; top: 0px">
<div id="content-area" class="clearfix">

<div id="left-area">

<div id="breadcrumbs" class="clearfix">

<a href="http://www.domain.com" class="breadcrumbs_home">Home</a> <span class="raquo">&raquo;</span>

</div> <!-- end #breadcrumbs --> <article id="post-21" class="post-21 page type-page status-publish hentry entry clearfix">

<div class="post_content clearfix">

<h1 class="title">Home</h1>

<h1 style="text-align: center;"></h1>

<?php
//in middle:
require('./templates/midbanner.php');

// I killed some code here, looked like you were doing double duty.

//You will only get one row back so you do not need to loop through, my bad for not correcting you on that the other day

echo "<table>";

echo "<tr>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td>" . $row['Ingredients'] . "</td>";
echo "<td>" . $row['Method'] . "</td>";
echo "</tr>";

echo "</table>";
?>

</div> <!-- end .post_content -->

</article> <!-- end .entry -->

</div> <!-- end #left-area -->

<?php
//in middle:
require('./templates/sidebar.php');
?>

</div> <!-- end #content-area -->

</div> <!-- end .container -->

</div> <!-- end #main-area --></center>

<?php
//in middle:
require('./templates/footer.php');
?>

<script type="text/javascript" src="jquery.form.min.js"></script>

<script type="text/javascript" src="superfish.js"></script>

<script type="text/javascript" src="jquery.fitvids.js"></script>

<script type="text/javascript" src="custom.js"></script>
</body>
</html>

---------------------------------------------------------------------------

I got rid of the stuff you posted today and I moved all the code we did a few days ago to the top of the file.

In the new code you did today, you were doing another connection and another query using a new methodology. WHY?????

You already had a pdo connection that works, move it to the top of the page and use it. Rarely will you need more than one database connection in any one particular program.

All the data you need is in the same table in 1 record, you only need one query to pull all the data you need.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote