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

sarettah 09-08-2021 04:54 PM

No problem. You are welcome.

.


All times are GMT -7. The time now is 11:16 PM.

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