Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 08-28-2021, 10:58 AM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
What a wild 3 weeks (and php question).

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
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-28-2021, 09:40 PM   #2
k33n
Confirmed User
 
Join Date: Feb 2009
Posts: 201
Print $sql and make sure the query is valid...i don't think you are passing the $GET['id'] value. And, you say that you want the RecipeID column but you are querying id column, it will fail because your table doesn't have a column "id".
k33n is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-28-2021, 09:52 PM   #3
Colmike9
(>^_^)b
 
Colmike9's Avatar
 
Industry Role:
Join Date: Dec 2011
Posts: 7,224
// check incoming params exist
if ( ! isset($_GET['id'] ) {
// missing param, go to an error page for example
header('Location: index.php');
exit;
}


is missing a )
__________________
Join the BEST cam affiliate program on the internet!
I've referred over $1.7mil in spending this past year, you should join in.
I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..
Colmike9 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-28-2021, 11:34 PM   #4
hornyasf
Confirmed User
 
Industry Role:
Join Date: Jul 2021
Posts: 185
Another tiny error

" echo $e-getMessage(); "

Missing a >
__________________
hornyasf is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 07:44 AM   #5
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by Colmike9 View Post
// check incoming params exist
if ( ! isset($_GET['id'] ) {
// missing param, go to an error page for example
header('Location: index.php');
exit;
}


is missing a )
Thank you!
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 07:44 AM   #6
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by hornyasf View Post
Another tiny error

" echo $e-getMessage(); "

Missing a >
Much appreciated
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 07:45 AM   #7
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by k33n View Post
Print $sql and make sure the query is valid...i don't think you are passing the $GET['id'] value. And, you say that you want the RecipeID column but you are querying id column, it will fail because your table doesn't have a column "id".
Could you show me where im messing up on that?

I tried changing it in a couple of spots and still running into 500 errors.

(Sorry only been working on php for a couple of months so still pretty green with it).

Thank you for the explanation
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 08:22 AM   #8
plsureking
bored
 
plsureking's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Metaverse
Posts: 4,675
hey if you still live in New Orleans stay safe and good luck! it doesn't look pretty.



#
__________________
#
plsureking is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 09:30 AM   #9
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by plsureking View Post
hey if you still live in New Orleans stay safe and good luck! it doesn't look pretty.



#
Thanks.

Its still relatively calm here right now, a little high wind and some light rain, that's about it (so far).

A few miles away several of the parishes have lost power and I'm seeing reports of flooding, still nothing majorly serious, we lose power and flood as a city all the time

The media (at this point in time) is definitely playing it up for ratings.
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 11:01 AM   #10
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
First, stay safe.

Second, as someone said above, you have an error in your if statement, you are missing a paren.

You have:

// check incoming params exist
if ( ! isset($_GET['id'] ) {
// missing param, go to an error page for example
header('Location: index.php');
exit;
}

That should be:

// check incoming params exist
if ( ! isset($_GET['id'] ) ){
// missing param, go to an error page for example
header('Location: index.php');
exit;
}


Thirdly:

In the recipe.php you do not establish a database connection. In the first program you are establishing a mysqli connection. In the Recipe.php you do not establish any database connection and then you try to use a pdo connection that does not exist.

Instead of mixing between mysqli and pdo, use one. You are using mysqli in the first program, use that again in the second. You use it at the bottom of the second to iterate through the rows.

Put an error_reporting(E_ALL) at the start of the program and it should show you your errors. Once you have everything debugged change that to error_reporting(0) so it won't show the errors.


<?php
error_reporting(E_ALL);

// check incoming params exist
if ( ! isset($_GET['id'] ) ){
// missing param, go to an error page for example
header('Location: index.php');
exit;
}

// open a mysqli connection
$con=mysqli_connect("localhost","recipes","passwor d","recipelist");

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

$table = "Recipes";
$sql = "SELECT * FROM" . $table . " WHERE id =" . $_GET['id'];

// do the query
$result = mysqli_query($con, $sql);

echo "<table>";
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>";
?>

Something like that should work. I have not checked to see if there are any other syntax issues.

You should also do some validation on $_GET['id']. I used it raw above and that is not really safe. It is fine for right now while you are trying to figure things out but for something open to the net it isn't.

For example is the id field an integer?

Then you would want to do a validation such as making sure it is an int coming in.

$recipeid=0;

if(isset($_GET['id']))
{
$recipeid=intval($_GET['id']);
}

if($recipeid==0)
{
echo "Bad id value coming in or something like that...";
}

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 11:36 AM   #11
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by sarettah View Post
First, stay safe.

Second, as someone said above, you have an error in your if statement, you are missing a paren.

You have:

// check incoming params exist
if ( ! isset($_GET['id'] ) {
// missing param, go to an error page for example
header('Location: index.php');
exit;
}

That should be:

// check incoming params exist
if ( ! isset($_GET['id'] ) ){
// missing param, go to an error page for example
header('Location: index.php');
exit;
}


Thirdly:

In the recipe.php you do not establish a database connection. In the first program you are establishing a mysqli connection. In the Recipe.php you do not establish any database connection and then you try to use a pdo connection that does not exist.

Instead of mixing between mysqli and pdo, use one. You are using mysqli in the first program, use that again in the second. You use it at the bottom of the second to iterate through the rows.

Put an error_reporting(E_ALL) at the start of the program and it should show you your errors. Once you have everything debugged change that to error_reporting(0) so it won't show the errors.


<?php
error_reporting(E_ALL);

// check incoming params exist
if ( ! isset($_GET['id'] ) ){
// missing param, go to an error page for example
header('Location: index.php');
exit;
}

// open a mysqli connection
$con=mysqli_connect("localhost","recipes","passwor d","recipelist");

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

$table = "Recipes";
$sql = "SELECT * FROM" . $table . " WHERE id =" . $_GET['id'];

// do the query
$result = mysqli_query($con, $sql);

echo "<table>";
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>";
?>

Something like that should work. I have not checked to see if there are any other syntax issues.

You should also do some validation on $_GET['id']. I used it raw above and that is not really safe. It is fine for right now while you are trying to figure things out but for something open to the net it isn't.

For example is the id field an integer?

Then you would want to do a validation such as making sure it is an int coming in.

$recipeid=0;

if(isset($_GET['id']))
{
$recipeid=intval($_GET['id']);
}

if($recipeid==0)
{
echo "Bad id value coming in or something like that...";
}

.
Damn! Thank you so much for the detailed response

Going to see if I can get this working with those fixes you made and the changes.

Out of interest, is there a specific time/reason I should use mysqli vs PDO in this type of scripting? Also, is there any significant difference in using echo vs print for the output data?

Winds are starting to pick up, no real damage here as yet though (2 miles outside the Quarter) unless you count a couple of upturned garbage cans that weren't secured properly by neighbors.

Power and Internet is still working, there was an advisory an hour or so back not to use dishwashers, washing machines or other appliances that utilize a lot of water due to the sewerage plant system losing power, other than that, nothing major to report here yet.

Have enough food, smokes and liquor to last a week if the power does go out and I just finished a huge pan of baked ziti, so should be somewhat comfortable if utilities do get knocked out at this point.

Again, thank you so much for your detailed reply, going to play around with this now.

#Quick Editing#

Yes, RecipeID goes from 001 through 3600 at the present time so will look into validation of that to protect from SQL injection once I have this working how I want before setting the whole thing live.

I honestly didn't think this pet project would take so long to get up and running, but I'm glad its finally in the process of being built haha
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 11:41 AM   #12
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
edited in: This got posted while you were posting apparently. It is not meant as a response ot your last post but rather a continuation of my post.

.................................................. ...

OP, You had posted about this same program a while back.

https://gfy.com/fucking-around-and-b...-web-page.html

Did you revisit that thread at all? Vdbucks gives a nice solution there. You should study the code that he, I and several other people have shown you. If you don't understand the code that you are looking at, play with it, ask questions, play with it some more until you understand exactly what it is doing and why it is doing it.

The recipe.php you posted indicates to me that you did not really examine the code at all before yelling for help. If you had, you would see that the comments in there are trying to guide you through how to use it but are not actually providing the code you should be using. For example, it says:

Quote:
// 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
It then shows you the code you might choose to use if you had a pdo connection established. It was not intended to be just run, it was intended to be modified before being run.

A programmer should never use code that they do not fully understand. Just my opinion, of course.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 11:43 AM   #13
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Quote:
Originally Posted by Publisher Bucks View Post
Out of interest, is there a specific time/reason I should use mysqli vs PDO in this type of scripting? Also, is there any significant difference in using echo vs print for the output data?
Nope. I just went with the mysqli because you already had a working connection in the first program.

Myself, I almost always use pdo because it makes the code more portable in that pdo will work with many different databases while mysqli is mysql specific.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 11:46 AM   #14
k33n
Confirmed User
 
Join Date: Feb 2009
Posts: 201
Sarettah's approach is better but for learning purposes, check the red notes. Tested.

Code:
<?php
    // 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=yourdbname", "dbusername","dbpass");
    $table = "Recipes";
   //3. Your query was looking for a column called id, but your column is called RecipeID
   //use this instead
      $sql = "SELECT * FROM $table WHERE RecipeID = :id";
    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();
    }
    //Added the table as i've seen a </table> below
    echo "<table border='1'>
			<tr>
			<th>ID</th>
			<th>Title</th>
			<th>Method</th>
			<th>Ingredients</th>
			</tr>";
    foreach ( $rows as $row ) {
        // do things with the $row['column_name'] data
       echo "<tr>";
       echo "<td>" . $row['Title'] . "</td>";
       echo "<td>" . $row['Ingredients'] . "</td>";
       echo "<td>" . $row['Method'] . "</td>";
       echo "</tr>";
    }
  // 4. You are using PDO, mysqli_fetch_array($result) will throw error:  mysqli_fetch_array() expects parameter 1 to be mysqli_result.And $result is undefined.   

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>";
?>
k33n is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 11:47 AM   #15
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by sarettah View Post
Did you revisit that thread at all? Vdbucks gives a nice solution there. You should study the code that he, I and several other people have shown you. If you don't understand the code that you are looking at, play with it, ask questions, play with it some more until you understand exactly what it is doing and why it is doing it
.
I tried running a search on the board for it but couldn't find it, I remembered posting about this issue a few weeks back before getting the rona, just didn't see it in the results.
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 11:59 AM   #16
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by sarettah View Post
Nope. I just went with the mysqli because you already had a working connection in the first program.

Myself, I almost always use pdo because it makes the code more portable in that pdo will work with many different databases while mysqli is mysql specific.

.
So that being said, would it be prudent for me to start utilizing pdo instead of mysqli if there range of databases is larger, will pdo allow me any benefit other than a wider range of database usage overall?
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 12:00 PM   #17
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by k33n View Post
Sarettah's approach is better but for learning purposes, check the red notes. Tested.

Code:
<?php
    // 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=yourdbname", "dbusername","dbpass");
    $table = "Recipes";
   //3. Your query was looking for a column called id, but your column is called RecipeID
   //use this instead
      $sql = "SELECT * FROM $table WHERE RecipeID = :id";
    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();
    }
    //Added the table as i've seen a </table> below
    echo "<table border='1'>
			<tr>
			<th>ID</th>
			<th>Title</th>
			<th>Method</th>
			<th>Ingredients</th>
			</tr>";
    foreach ( $rows as $row ) {
        // do things with the $row['column_name'] data
       echo "<tr>";
       echo "<td>" . $row['Title'] . "</td>";
       echo "<td>" . $row['Ingredients'] . "</td>";
       echo "<td>" . $row['Method'] . "</td>";
       echo "</tr>";
    }
  // 4. You are using PDO, mysqli_fetch_array($result) will throw error:  mysqli_fetch_array() expects parameter 1 to be mysqli_result.And $result is undefined.   

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>";
?>
Thank you!

I appreciate the notes, always good to learn from mistakes and understanding why it didn't work is a huge plus
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 12:07 PM   #18
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Quote:
Originally Posted by Publisher Bucks View Post
So that being said, would it be prudent for me to start utilizing pdo instead of mysqli if there range of databases is larger, will pdo allow me any benefit other than a wider range of database usage overall?
Concentrate on one thing at a time.

You are close to having a working solution using mysqli. So, if I were you, I would get what I have working and make sure I understand what is going on and why I used each and every comment and function that I used.

Then If I want to play with pdo, make a copy and change it out to work with pdo.

Then I would probably make another copy and turn the whole thing into an class and do an object oriented cut of it.

Each time it will increase your knowledge.

Earlier I forgot to answer you about echo versus print. They are bascially the same in common usage. There are differences. Print returns a value of 1 while echo does not and echo can take multiple parameters.

As I said in the earlier thread php.net is your friend.

https://www.php.net/manual/en/function.echo.php

https://www.php.net/manual/en/function.print.php

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 12:09 PM   #19
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Quote:
Originally Posted by Publisher Bucks View Post
I tried running a search on the board for it but couldn't find it, I remembered posting about this issue a few weeks back before getting the rona, just didn't see it in the results.
For future reference, since you started the thread just do a search for all threads started by you and you can find it pretty easily.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 12:15 PM   #20
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by sarettah View Post
For future reference, since you started the thread just do a search for all threads started by you and you can find it pretty easily.

.
Thanks, I would have just added to that thread if I'd found it LOL
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 12:16 PM   #21
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by sarettah View Post
Concentrate on one thing at a time.

You are close to having a working solution using mysqli. So, if I were you, I would get what I have working and make sure I understand what is going on and why I used each and every comment and function that I used.

Then If I want to play with pdo, make a copy and change it out to work with pdo.

Then I would probably make another copy and turn the whole thing into an class and do an object oriented cut of it.

Each time it will increase your knowledge.

Earlier I forgot to answer you about echo versus print. They are bascially the same in common usage. There are differences. Print returns a value of 1 while echo does not and echo can take multiple parameters.

As I said in the earlier thread php.net is your friend.


.
Good points, thank you again for all your help and advice on this project of mine, I really appreciate it
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 12:17 PM   #22
CaptainHowdy
Too lazy to set a custom title
 
CaptainHowdy's Avatar
 
Industry Role:
Join Date: Dec 2004
Location: Happy in the dark.
Posts: 93,011
sarettah . . . too useful (and scarcely spiteful) for this board.
__________________
FLASH SALE INSANITY! deal with a 100% Trusted Seller
Buy Traffic Spots on a High-Quality Network

1 Year or Lifetime — That’s Right, Until the Internet Explodes!
CaptainHowdy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2021, 03:54 PM   #23
plsureking
bored
 
plsureking's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Metaverse
Posts: 4,675
Quote:
Originally Posted by CaptainHowdy View Post
sarettah . . . too useful (and scarcely spiteful) for this board.


#
__________________
#
plsureking is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 07:29 AM   #24
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
One last bump for this project as I have a related question...

What is the function called to be able to add certain data entries as I guess 'tags' for want of a better word without knowing the correct term?

What I'm trying to do is to include some of the SQL data to display in the HTML meta tags, so for example, it would pull the data from the row for the 'RecipeName' column and in the meta tags I'd like to put a snippet of code like below:

PHP Code:
<meta name="Keywords" content="Simple recipe for <?php include "RecipeName"?>" />
<meta name="Description" content="<?php include "RecipeName"?> recipe ingredients" />
Which would display...

<meta name="Keywords" content="Simple recipe for Cake" />
<meta name="Description" content="Cake recipe ingredients" />

Just trying to give this project a little SEO advantage, what is the function called that I need to use in order to do something like that in the template pages, that pulls directly from the SQL database for the RecipeName based on the same RecipeID in the URL?

TIA
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 07:34 AM   #25
plsureking
bored
 
plsureking's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Metaverse
Posts: 4,675
Quote:
Originally Posted by Publisher Bucks View Post
PHP Code:
Simple recipe for (phocode


#
__________________
#
plsureking is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 07:54 AM   #26
The Porn Nerd
Living The Dream
 
The Porn Nerd's Avatar
 
Industry Role:
Join Date: Jun 2009
Location: Inside a Monitor
Posts: 19,503
I love these coding threads!
I can't understand a single fucking word. LOL
__________________
My Affiliate Programs:
Porn Nerd Cash | Porn Showcase | Aggressive Gold

Over 90 paysites to promote!
Skype: peabodymedia
The Porn Nerd is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 08:00 AM   #27
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Sorry, forgot to post the code im using to attach the data from the database..

PHP Code:
<?php
session_start
();
(
"mysql:host=localhost;dbname=database""user","password");
    
$table "Recipes";

$metasettings = @mysql_fetch_assoc(@mysql_query("SELECT * FROM RecipeName, RecipeDescription, Author"));

$title $metasettings['RecipeName'];
$description $metasettings['RecipeDescription'];
$random_tags $metasettings['Author'];

?>
Then im using this in place on each of the metas..

PHP Code:
<?=$title?>
<?=$description?>
<?=$random_tags?>
Hope that makes sense
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 08:01 AM   #28
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by The Porn Nerd View Post
I love these coding threads!
I can't understand a single fucking word. LOL
I've only been coding a month or two so can barely understand it myself, hence this thread, I'm trying to learn though
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 08:12 AM   #29
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Quote:
Originally Posted by Publisher Bucks View Post
Sorry, forgot to post the code im using to attach the data from the database..

PHP Code:
<?php
session_start
();
(
"mysql:host=localhost;dbname=database""user","password");
    
$table "Recipes";

$metasettings = @mysql_fetch_assoc(@mysql_query("SELECT * FROM RecipeName, RecipeDescription, Author"));

$title $metasettings['RecipeName'];
$description $metasettings['RecipeDescription'];
$random_tags $metasettings['Author'];

?>
Then im using this in place on each of the metas..

PHP Code:
<?=$title?>
<?=$description?>
<?=$random_tags?>
Hope that makes sense
You want to print it in your head, right?

<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<meta name="description" content="<?php echo $description; ?>">
</head>
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 08:13 AM   #30
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Skip the base ref part... Somehow that got added.
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 08:38 AM   #31
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Quote:
Originally Posted by zijlstravideo View Post
Skip the base ref part... Somehow that got added.
Yeah the board does that.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 09:13 AM   #32
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Quote:
Originally Posted by sarettah View Post
Yeah the board does that.

.
It's alive!

By the way, to OP: I see you use include in the original code...
You would use include if you want to include a file. <?php include("path/to/file.php"); ?>
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 10:27 AM   #33
J. Falcon
www.AdultCopywriters.com
 
Industry Role:
Join Date: May 2006
Posts: 31,564
Glad you're feeling better.
__________________
Adult Copywriters



SEO Content for Porn Sites
sales at adultcopywriters dot com
J. Falcon is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 01:57 PM   #34
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by zijlstravideo View Post
You want to print it in your head, right?

<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<meta name="description" content="<?php echo $description; ?>">
</head>
That's what I've been doing but its not showing up, I think I'm messing up with the get/post for the variable in the connection part of my script.
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 01:59 PM   #35
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Quote:
Originally Posted by Publisher Bucks View Post
That's what I've been doing but its not showing up, I think I'm messing up with the get/post for the variable in the connection part of my script.
You have the php sql query code at the top?
Else the output will be empty.

Also I think you're missing the Recipes table in your query...
"SELECT RecipeName, RecipeDescription, Author FROM Recipes"
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 02:57 PM   #36
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057

I am looking through today's discussion and at this point I am pretty confused.

What tables are you using and what fields are in the tables?

I am seeing you use what I think are table names as output?

So, not sure what to tell you.

As zijlstravideo said, you need to be doing the query at the top of the page if you expect to output it in the head section.

Code:
<html>
<?php
Hook up to the database.
Get your input variables.
Do your query for the meta data
?>
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<title><?php echo your title here; ?php></title>
<meta name="keywords" value="<?php echo your keywords here; ?>">
<meta name="desctiption" value="<?php echo your description here; ?>">
</head>
<body>
<?php 
do your recipe query here
output your recipe table here
?>
</body>
</html>
Is kind of what the structure of the page should be, I think.

You are mixing methodologies it appears also.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 03:24 PM   #37
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
This is what the top of the HTML looks like presently on my test page:

PHP Code:
<?php
session_start
();
(
"mysql:host=localhost;dbname=database""user","password");
    
$table "Recipes";

$metasettings = @mysql_fetch_assoc(@mysql_query("SELECT * FROM $table WHERE RecipeName, RecipeDescription, Author"));

$title $metasettings['RecipeName'];
$description $metasettings['RecipeDescription'];
$random_tags $metasettings['Author'];

?>
<!DOCTYPE html>
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->


    <meta charset="UTF-8"/>

    <title><?php echo $title?> Recipe</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"/>
What I'm trying to do in the SQL data is to add the 'RecipeName', 'RecipeDescription' and 'Author' rows as meta tags.

The page is called by URL like this:

PHP Code:
recipes.php?id=34 
The recipes.php works perfectly, I just cant get this row data showing in the metas where I want them to, once I get this part working I can secure the id= stuff and set the site live, hopefully

Hope that makes sense than my rambling posts earlier
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 05:06 PM   #38
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
I know what you are trying to do. I am thouroghly confused by how you are trying to do it. Your code does not make sense to me.

Quote:
$metasettings = @mysql_fetch_assoc(@mysql_query("SELECT * FROM $table WHERE RecipeName, RecipeDescription, Author"));

$title = $metasettings['RecipeName'];
$description = $metasettings['RecipeDescription'];
$random_tags = $metasettings['Author'];
This looks all sorts of wrong to me.

Your query makes no sense.

SELECT * FROM $table WHERE RecipeName, RecipeDescription, Author

You say:
Quote:
What I'm trying to do in the SQL data is to add the 'RecipeName', 'RecipeDescription' and 'Author' rows as meta tags.
You select columns (field names) from a table then you read through the rows returned. Rows do not have names, unless this is some new fangled sql that I have never seen before.

What fields are in your table? The Recipes table we were working with before had the fields 'recipeid', 'title', 'method' and 'ingredients' in it.

It now has RecipeName, RecipeDescription and Author also?

If so then you need to pull those fields like you pulled the other fields from the table. You did that by calling for a result by id.

In this case you have not grabbed your input variable so you don't know what id the recipe you are pulling has.

What does the entire .php file look like right now?

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 05:29 PM   #39
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by sarettah View Post
What fields are in your table? The Recipes table we were working with before had the fields 'recipeid', 'title', 'method' and 'ingredients' in it.

It now has RecipeName, RecipeDescription and Author also?
Yes, they got added a few days back, so it contains the original ones plus those additional columns.
Quote:
If so then you need to pull those fields like you pulled the other fields from the table. You did that by calling for a result by id.
That just gets put at the top of the page still correct?

Quote:
What does the entire .php file look like right now?
As posted above or, do you mean the full code incl html for the recipes.php page?
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 05:50 PM   #40
The Porn Nerd
Living The Dream
 
The Porn Nerd's Avatar
 
Industry Role:
Join Date: Jun 2009
Location: Inside a Monitor
Posts: 19,503
Quote:
Originally Posted by Publisher Bucks View Post
I've only been coding a month or two so can barely understand it myself, hence this thread, I'm trying to learn though
GFY is a great place to learn! Lots of excellent coders on here.
__________________
My Affiliate Programs:
Porn Nerd Cash | Porn Showcase | Aggressive Gold

Over 90 paysites to promote!
Skype: peabodymedia
The Porn Nerd is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 05:54 PM   #41
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Quote:
Originally Posted by Publisher Bucks View Post
Yes, they got added a few days back, so it contains the original ones plus those additional columns.


That just gets put at the top of the page still correct?



As posted above or, do you mean the full code incl html for the recipes.php page?

I know where the issue is at this point.

Post the entire recipes.php page so I can kind of walk you through the mess.

please.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 05:59 PM   #42
plsureking
bored
 
plsureking's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Metaverse
Posts: 4,675
Quote:
Originally Posted by The Porn Nerd View Post
GFY is a great place to learn! Lots of excellent coders on here.
better coders than corporate

#
__________________
#
plsureking is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 06:07 PM   #43
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Ok, you need to think through what you are doing some.

You are using different methodologies within the same page I think. That makes no sense.

Before this, in prior discussions you hooked up to the database and you got your input variables.

Then you did your query using the id that was passed in as your key.

You only need to do that once and you need to do it at the very beginning of the program.

Then you have all the data you need to do everything else.

It looks to me (from what you posted) that you are trying to do 2 queries. The one you posted today that is totally discombobulated and the one you were doing during the hurricane which we had figured out.

You only need one query. But it has to occur before you output anything.

So your flow becomes:

Get your input variable.
Hook up to the database. (these 2 items can be done in either order)
Do your query
grab your results
present your data.

Once you put up the code I will try to show you what I mean.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 06:11 PM   #44
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
By the way, anybody looking at this, it still helps to draw out a logic flow. You shouldn't be coding anything without some sort of flow chart drawn out until you have a whole lot of experience under your belt.

Even then, once you have experience it helps to draw it out., Some of us have been around long enough to do flow charts and entity diagrams in our head. beginners should not be doing that.

I wrote my first computer code 49 years ago. I still draw out the flow. I even use symbols when I want to explain it to others.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 06:15 PM   #45
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by sarettah View Post
I know where the issue is at this point.

Post the entire recipes.php page so I can kind of walk you through the mess.

please.

.
Thank you (again!).

PHP Code:
<?php
session_start
();
(
"mysql:host=localhost;dbname=database""user","password");
    
$table "Recipes";

$metasettings = @mysql_fetch_assoc(@mysql_query("SELECT * FROM $table WHERE RecipeName, RecipeDescription, Author"));

$title $metasettings['RecipeName'];
$description $metasettings['RecipeDescription'];
$random_tags $metasettings['Author'];

?>
<!DOCTYPE html>
<head>
<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"/>

    {-- removed all the random css testing crap --}

        </head>

<body class="home page page-id-21 page-template-default ie et_includes_sidebar">

        <?php
//in middle:
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> <!-- end .container -->

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

[b]included in secondary.php is a search function too, do you need to see the code for that?[/b]

    <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'); 
 
?>

<?php
// 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";
      
$sql "SELECT * FROM $table WHERE ID = :id";
    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
       
echo "<tr>";
       echo 
"<p><h2>" $row['Title'] . " Recipe.</h2></p>";

       echo 
"<p><b>Ingredients</b></p>";
       echo 
"<p> " $row['Ingredients'] . "</p>";
       echo 
"<p><b>Method</b></p>";
       echo 
"<p>" $row['Method'] . "</p>";
       echo 
"</tr>";
    }
  
// 4. You are using PDO, mysqli_fetch_array($result) will throw error:  mysqli_fetch_array() expects parameter 1 to be mysqli_result.And $result is undefined.   

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>";
?>

                                </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>
Like I say, the recipes.php page works for everything else, its just not letting me throw the meta tag data in that I'd like to use.

The TABLE 'Recipes' contains the following columns...

RecipeID
Title
Description (not used but has data in it)
Ingredients
Method
Nutritional (not used but has data in it)
RecipeName (for metas)
RecipeDescription (for metas)
Author (for metas)

The last 3 are the only thing that was added 'new' to the table since last week. Although thinking about it now, I could probably use 'Title' instead of the 'RecipeName' data as its pretty much the same thing.
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 06:29 PM   #46
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 online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 06:40 PM   #47
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Now, do you understand all that?

If not, ask questions. Play with the code. Figure out what each and every statement does and why it is there.

Some things have to be done in a certain order, some things don't.

You have to have the input variable for the id before you do the query because the query depends on the id.

You have to have a database connection before you can do the query.

You have to do the query before you can output anything from the database.

Also, not to be rude or mean but where the fuck did you get this from?

"SELECT * FROM RecipeName, RecipeDescription, Author";

Which you later changed to this:

"SELECT * FROM $table WHERE RecipeName, RecipeDescription, Author";

That was what was really throwing me for a loop. I was thinking the original

"SELECT * FROM RecipeName, RecipeDescription, Author" Might be attempting to do a 3 table join of some sort.


.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 06:53 PM   #48
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Btw, I did a last minute change just now. Changed the fetch all to fetch assoc.

The other changes I made would have been wrong with the fetchall in there, I missed it the first time through.

I also removed your session_start().

I saw no evidence in any of the code you posted that you were using sessions. If you are then you will want to put that back in.

Also, please stop using the [ PHP ] tag around the code. Makes it really difficult to read.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 07:19 PM   #49
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,057
Sorry to carry on but.

You said:
Quote:
Like I say, the recipes.php page works for everything else, its just not letting me throw the meta tag data in that I'd like to use.
Really? it shouldn't have. You had pdo stuff and mysqli stuff mixed together in there, should have been throwing errors out the wazoo on you.

It doesn't look like you have error reporting turned on. If you can't see the errors you cannot fix them. PHP is a very forgiving language a lot of times, that is detrimental for a beginning coder.

Puth the command: error_reporting[E_ALL]; at the very top of the program, once you have all the errors debugged then change it to error_reorting[0]; anytime you neeed to debug change it back to E_ALL . E_ALL tells it to show you all errors no matter how small. A beginner should NOT be ignoring any errors.

Just all imho of course.

.
__________________
All cookies cleared!
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-06-2021, 07:41 PM   #50
ruff
I have a plan B
 
ruff's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Seattle - Miami - St Kitts
Posts: 5,501
Quote:
Originally Posted by The Porn Nerd View Post
I love these coding threads!
I can't understand a single fucking word. LOL
I read everything here. Didn't understand shit, but I admire smart people.
__________________
CryptoFeeds
ruff is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
page, weeks, code, website, wild, supposed, told, covid, issue, index, recipes.php, messed, guidance, clicked, generated, link, recipes.php?id=4, ago, telling, site, recipe, clue, php, vomiting, finally



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.