GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech What a wild 3 weeks (and php question). (https://gfy.com/showthread.php?t=1347823)

sarettah 09-06-2021 05:54 PM

Quote:

Originally Posted by Publisher Bucks (Post 22910423)
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.

.

plsureking 09-06-2021 05:59 PM

Quote:

Originally Posted by The Porn Nerd (Post 22910429)
GFY is a great place to learn! Lots of excellent coders on here. :thumbsup

better coders than corporate :drinkup

#

sarettah 09-06-2021 06:07 PM

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.

.

sarettah 09-06-2021 06:11 PM

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.

.

Publisher Bucks 09-06-2021 06:15 PM

Quote:

Originally Posted by sarettah (Post 22910432)
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.

sarettah 09-06-2021 06:29 PM

<?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.

.

sarettah 09-06-2021 06:40 PM

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.


.

sarettah 09-06-2021 06:53 PM

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.

.

sarettah 09-06-2021 07:19 PM

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.

.

ruff 09-06-2021 07:41 PM

Quote:

Originally Posted by The Porn Nerd (Post 22910196)
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.:thumbsup

sarettah 09-06-2021 07:54 PM

Fiddy PHP Errors....


Just realized, you pull author into a field called random_tags but you never do use it any where.

.

sarettah 09-06-2021 08:22 PM

Quote:

Originally Posted by sarettah (Post 22910466)
Put 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.
.

man, I fucked that up.

the command is error_reporting(E_ALL);

damn.

.

Publisher Bucks 09-06-2021 08:34 PM

Quote:

Originally Posted by sarettah (Post 22910479)
Fiddy PHP Errors....


Just realized, you pull author into a field called random_tags but you never do use it any where.

.

Yeah, thats for something a little further along the line, when it comes to adding new recipes to the DB via a form on the site.

Playing with the code you posted now, shall report back in a little while, thank you again for your help with this php stuff, I really appreciate your time and assistance :thumbsup

sarettah 09-06-2021 08:46 PM

A cleaner version. More my style. No camelcase shit ;p

<?php
error_reporting(E_ALL);

$id=0;
if ( ! isset($_GET['id'] ) )
{
header('Location: index.php');
}
else
{
$id=intval($_GET['id']);
}
if($id==0)
{
die('bad id passed in');
}

$pdo=hookitup();

$table = "recipes";
$sql = "select * from " . $table . " where id=?";

try
{
$stmt = $db->prepare($sql_str);
$stmt->execute(array($pdo->quote($id)));
}
catch( PDOException $e)
{
die($e-getMessage());
}

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

$title = $row['recipename'];
$description = $row['recipedescription'];

?>
<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 http-equiv="Content-Type" content="text/html; 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"/>

<link rel="canonical" href="//siteurl/">
</head>

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

<?php
require_once('./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>

<?php
require_once('./templates/secondary.php');
?>

<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>
<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>
<?php
require_once('./templates/midbanner.php');

echo "<table>";
echo "<tr>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['ingredients'] . "</td>";
echo "<td>" . $row['method'] . "</td>";
echo "</tr>";
echo "</table>";
?>
</div>
</article>
</div>
<?php
require_once('./templates/sidebar.php');
?>
</div>
</div> <!-- end .container -->
</div> <!-- end #main-area --></center>

<?php
require_once('./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>

<?php

function hookitup()
{
require_once('dbcreds.php');
return new PDO("mysql:host=$host;dbname=$dbname;charset=utf8" ,$user,$password,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}

In dbcreds.php would be:

<?php
$dbname='dbname';
$dbuser='dbusername';
$dbpass='dbpassword';
$dbhost='localhost';
?>

.

zijlstravideo 09-07-2021 06:08 AM

A small addition to the code above:

$title = ucwords($row['recipename']);
//Personal taste, but I like titles like that. The above makes each first character of a word uppercase: This Is A Great Title

$description = ucfirst($row['recipedescription']);
//Makes the first character of your string uppercase (in case it isn't stored that way in the database. It looks pretty bad in the search results if your description's first letter isn't uppercase.

Publisher Bucks 09-07-2021 08:47 PM

Apologies for the late response, we lost power again last night while they were working on the lines to try and get the rest of the neighborhood up and running.

I played with the code you posted and seem to be getting a weird error where the data from the SQL isn't showing, its just giving me a blank page and there are no meta tags showing up either. (Didn't change anything until after the blank page showed).

Putting back the original code, the page works how it is supposed to, any thoughts? :Oh crap

k33n 09-07-2021 09:35 PM

Code:

$sql = "select * from " . $table . " where id=?";

try
{
$stmt = $db->prepare($sql_str);

Replace $sql_str with $sql

Publisher Bucks 09-07-2021 10:01 PM

Quote:

Originally Posted by k33n (Post 22910929)
Code:

$sql = "select * from " . $table . " where id=?";

try
{
$stmt = $db->prepare($sql_str);

Replace $sql_str with $sql

K33n,

I gave that a try and its still showing a blank page, this is the error from the logs:

Quote:

#0 /blah/blah/domain.com/recipesnew.php(119): PDO->__construct('mysql:host=;dbn...', NULL, NULL, Array)
#1 /blah/blah/domain.com/recipesnew.php(18): hookitup()
#2 {main}
thrown in /blah/blah/domain.com/recipesnew.php on line 119

zijlstravideo 09-08-2021 02:27 AM

Quote:

Originally Posted by Publisher Bucks (Post 22910939)
K33n,

I gave that a try and its still showing a blank page, this is the error from the logs:

function hookitup()
{
require_once('dbcreds.php');
return new PDO("mysql:host=$host;dbname=$dbname;charset=utf8" ,$user,$password,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}

dbcreds file:
<?php
$dbname='dbname';
$dbuser='dbusername';
$dbpass='dbpassword';
$dbhost='localhost';
?>

These two don't match, that's why you're getting a blank page (as no database connection is being made).


Change the function to:

function hookitup()
{
require_once('dbcreds.php');
return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf8" ,$user,$password,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}

And as K33n noted, change:

$stmt = $db->prepare($sql_str);

to:

$stmt = $db->prepare($sql);

zijlstravideo 09-08-2021 03:51 AM

To OP: You can learn a lot from looking more closely to your error log. This one was easy to spot.

Your error: #0 /blah/blah/domain.com/recipesnew.php(119): PDO->__construct('mysql:host=;dbn...', NULL, NULL, Array)

See how host= is empty...

Publisher Bucks 09-08-2021 05:35 AM

Quote:

Originally Posted by zijlstravideo (Post 22910971)
function hookitup()
{
require_once('dbcreds.php');
return new PDO("mysql:host=$host;dbname=$dbname;charset=utf8" ,$user,$password,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}

dbcreds file:
<?php
$dbname='dbname';
$dbuser='dbusername';
$dbpass='dbpassword';
$dbhost='localhost';
?>

These two don't match, that's why you're getting a blank page (as no database connection is being made).


Change the function to:

function hookitup()
{
require_once('dbcreds.php');
return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf8" ,$user,$password,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}

And as K33n noted, change:

$stmt = $db->prepare($sql_str);

to:

$stmt = $db->prepare($sql);

Thank you.

Its still not showing anything BUT, does that mean I also need to make the following changes based on this error?

Quote:

#0 /blah/blah/domain.com/recipesnew.php(118): PDO->__construct('mysql:host=loca...', NULL, NULL, Array)
#1 /blah/blah/domain.com/recipesnew.php(18): hookitup()
#2 {main}
thrown in /blah/blah/domain.com/recipesnew.php on line 118
return new PDO("mysql:host=$dbhost;dbname=$dbname" ,$dbuser,$dbpass,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}

Or am I looking in the wrong place/overthinking and doing the wrong thing?

zijlstravideo 09-08-2021 06:12 AM

Yup, good catch. Those as well.

sarettah 09-08-2021 07:25 AM

Sorry about that. I didn't do a full test and that kind of shit happens when you meld 2 different sets of code together.

In this case, I grabbed my dbcreds file from my local machine and my hookup routine from a different place.

But that is what debugging is for, ya know?

I really didn't think you were just going to switch out to the new code I posted, I was just trying to get to a code set that made sense to me.

.

Publisher Bucks 09-08-2021 07:52 AM

Quote:

Originally Posted by zijlstravideo (Post 22911006)
Yup, good catch. Those as well.

I'm still missing something though as its giving a 500 error.

Quote:

Stack trace:
#0 /blah/blah/domain.com/recipesnew.php(118): PDO->__construct('mysql:host=loca...', NULL, NULL, Array)
#1 /blah/blah/domain.com/recipesnew.php(18): hookitup()
#2 {main}
thrown in /blah/blah/domain.com/recipesnew.php on line 118

Which makes no sense as I made those changes already :Oh crap

sarettah 09-08-2021 07:56 AM

Quote:

Originally Posted by Publisher Bucks (Post 22911025)
I'm still missing something though as its giving a 500 error.



Which makes no sense as I made those changes already :Oh crap

What does line 118 look like in your program?

From the error you posted it appears that you do not have anything populated into your $dbuser and $dbpass variables.

But post line 118 of the program, please.

.

Publisher Bucks 09-08-2021 07:57 AM

Quote:

Originally Posted by sarettah (Post 22911014)
Sorry about that. I didn't do a full test and that kind of shit happens when you meld 2 different sets of code together.

In this case, I grabbed my dbcreds file from my local machine and my hookup routine from a different place.

But that is what debugging is for, ya know?

I really didn't think you were just going to switch out to the new code I posted, I was just trying to get to a code set that made sense to me.

.

No apologies needed, I'm learning so figured grabbing your code was the easiest way to figure out what I'm actually fucking up on my end of things and having a 'working' code (that doesn't on occasion) is a good way for me to screw around and check what isn't working and why :)

I'm really appreciative of everyone's help, assistance and knowledge in this thread as I'm sure you all have other things you could be doing instead of sharing your expertise.

Publisher Bucks 09-08-2021 08:00 AM

Quote:

Originally Posted by sarettah (Post 22911026)
What does line 118 look like in your program?

.

Line 118 in recipesnew.php is:

Quote:

return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf 8" ,$dbuser,$dbpass,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
Also, a quick question sarettah, what is the purpose of having the charset=utf8 in there? Wont it do the same thing without that? Just pull the databases name, or is that a security thing?

zijlstravideo 09-08-2021 08:28 AM

Quote:

Originally Posted by sarettah (Post 22911014)
Sorry about that. I didn't do a full test and that kind of shit happens when you meld 2 different sets of code together.

In this case, I grabbed my dbcreds file from my local machine and my hookup routine from a different place.

But that is what debugging is for, ya know?

I really didn't think you were just going to switch out to the new code I posted, I was just trying to get to a code set that made sense to me.

.

Lol, it's always those small things that mess things up. I once wasted an entire day because I had a white space in the $dbpass = "pass "; :1orglaugh:helpme

By the way, I think you can even shorten this:

$id=0;
if ( ! isset($_GET['id'] ) )
{
header('Location: index.php');
}
else
{
$id=intval($_GET['id']);
}
if($id==0)
{
die('bad id passed in');
}

Into:

$id=intval($_GET['id']);
if($id==0)
{
header( "Location: index.php" ); //or any other page like 404
exit;
}

As intval will also output 0 if $id is empty.

sarettah 09-08-2021 08:44 AM

Quote:

Originally Posted by Publisher Bucks (Post 22911028)
Line 118 in recipesnew.php is:



Also, a quick question sarettah, what is the purpose of having the charset=utf8 in there? Wont it do the same thing without that? Just pull the databases name, or is that a security thing?

Your error: /blah/blah/domain.com/recipesnew.php(118): PDO->__construct('mysql:host=loca...', NULL, NULL, Array)

indicates that you are not passing in a username or password. The places that say NULL, NULL right before the Array indicate that $dbuser and $dbpass are coming in as NULL meaning there ain't nothing there.

Your error: /blah/blah/domain.com/recipesnew.php(118): PDO->__construct('mysql:host=loca...', NULL, NULL, Array)

PDO("mysql:host=$dbhost;dbname=$dbname" ,$dbuser,$dbpass,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}


So, if you are using the dbcreds.php file then the problem is in there. If you are not using that and have the user and password hardcoded then that would be where the issue is.


The charset=utf8 just tells it to accept utf8 characters. The routine I pulled it from has to handle various different languages. I pretty much have everything I do coded for utf8 (unicode).

.

sarettah 09-08-2021 08:47 AM

Quote:

Originally Posted by zijlstravideo (Post 22911040)
Lol, it's always those small things that mess things up. I once wasted an entire day because I had a white space in the $dbpass = "pass "; :1orglaugh:helpme

By the way, I think you can even shorten this:

$id=0;
if ( ! isset($_GET['id'] ) )
{
header('Location: index.php');
}
else
{
$id=intval($_GET['id']);
}
if($id==0)
{
die('bad id passed in');
}

Into:

$id=intval($_GET['id']);
if($id==0)
{
header( "Location: index.php" ); //or any other page like 404
exit;
}

As intval will also output 0 if $id is empty.

Yep, that would work.

I tend to, when trying to do code 101 stuff use old old school. First step intialize variable to default value then use it.

But yeah you are initializing it to whatever comes into the get if it is a valid int or zero if not so it does the same thing in a couple of less words.

.

Publisher Bucks 09-08-2021 10:02 AM

Quote:

Originally Posted by sarettah (Post 22911044)
indicates that you are not passing in a username or password. The places that say NULL, NULL right before the Array indicate that $dbuser and $dbpass are coming in as NULL meaning there ain't nothing there.

Okay, I think it has something to do with this part at the bottom of the coding (my version)...

Quote:

{
require_once('dbcreds.php');
return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf 8" ,$username,$password,array(PDO::ATTR_EMULATE_PREPA RES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
So, if you are using the dbcreds.php file then the problem is in there. If you are not using that and have the user and password hardcoded then that would be where the issue is.

This is the dbcreds.php file that is being used:

Quote:

$dbname='database';
$dbuser='user';
$dbpass='password';
$dbhost='localhost'
Am I right in assuming the above code should look like this on the bottom of recipesnew.php:

Quote:

{
require_once('dbcreds.php');
return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf 8" ,$dbuser;$dbpass,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
Because I tried changing the dbpassword part and it still shows a blank page, I know 100% the information in the dbcreds.php is correct and there was a mismatch of the naming, which I (think) I corrected? Or does that entire string need to be included in quotation marks like this...

Quote:

{
require_once('dbcreds.php');
return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf8;$d buser;$dbpass",array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
I think I'm confusing myself with the edits somewhere in this specific section :Oh crap

sarettah 09-08-2021 11:32 AM

The code you are posting looks right The bottom part you posted at the end where you moved the quote marks is wrong.

The part of the error you are showing us indicated that there is nothing in the username and password variables which would mean the problem is in the dbcreds.php like I said earlier.

I have sent you a pm.

.

sarettah 09-08-2021 11:53 AM

I sent this via pm also but

in the dbcreds.php you are missing a semicolon after localhost

$dbhost='localhost'

Should be

$dbhost='localhost';


.

sarettah 09-08-2021 12:04 PM

In the code you sent me:

return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf 8" ,dbuser=$dbuser;dbpass=$dbpass,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

should be:

return new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf 8",$dbuser,$dbpass,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

You added an equals sign in the dbuser and dbpass that should not be there.

There is still an issue in the code. I am looking.

.

sarettah 09-08-2021 12:11 PM

On line 15-17 you have a try statement that is not completed:

try
{
$sql = "select * from " . $table . " where id=?";

Get rid of that.

.

sarettah 09-08-2021 12:27 PM

A mistake in the code I posted.

around line 16:

try
{
$stmt = $db->prepare($sql);
}
catch( PDOException $e)
{
die($e-getMessage());
}

should be:

try
{
$stmt = $pdo->prepare($sql);
}
catch( PDOException $e)
{
die($e-getMessage());
}

.

sarettah 09-08-2021 12:32 PM

Damn I suck today :(

Another issue in what I posted:

try
{
$stmt = $pdo->prepare($sql);
}
catch( PDOException $e)
{
die($e-getMessage());
}

Should be:

try
{
$stmt = $pdo->prepare($sql);
}
catch( PDOException $e)
{
die($e->getMessage());
}

.

sarettah 09-08-2021 12:42 PM

Also, (this one is not my mistake) you removed the execute statement from that same code block.

So:

try
{
$stmt = $pdo->prepare($sql);
}
catch( PDOException $e)
{
die($e->getMessage());
}

Should be:

try
{
$stmt = $pdo->prepare($sql);
$stmt->execute(array($pdo->quote($id)));
}
catch( PDOException $e)
{
die($e->getMessage());
}

sarettah 09-08-2021 04:05 PM

Well, that was fun.

To whoever was watching, the OP and I took it private so I could see the actual code without revealing any proprietary info.

It looks like he is in pretty good shape now.

It was mainly syntax issues.

.

Publisher Bucks 09-08-2021 04:06 PM

sarettah,

I just want to say thank you for all of your help, not only in this thread over the past week but also by PM, you truly do not know how appreciative I am of your time helping me to get this pet project working, I'm sure there are a hundred other things you could have been doing this afternoon instead of spending time to get this working for me.

I'm going to play around with a couple of other formatting issues that I'm having but other than that, I am really happy with how this site has turned out, even though its just a pet project of mine and not really going to be a money maker its good to start seeing it come to fruition :)

Thank you so much :thumbsup


All times are GMT -7. The time now is 02:07 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123