collecting data from html template for php script

Can you disseminate the URL for me, http://eyewasframed.co/public_html/prac.php?

Why do you have a folder named “public_html”? If it is referring to your public_html directory, DONT DO THAT!!! Your domain automatically routes to your public_html/ directory. Try your url like the, http://eyewasframed.co/prac.php and throw an echo in so you know it is working!

here’s the catch. when i enter the url in firefox i get a blank page, when entering it in chrome i get a error 500 message. (see below)

I attempted to put another echo in the top of the script:
[php]<?php
error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
print_r($_POST);
die(“Got Here…Connections-order.php”);
echo “An Error Occurred. The Error Is Being Processed!”;

?>
Untitled Document <?php /*** mysql hostname ***/ $hostname = 'xxxx.co'; /*** mysql username ***/ $username = 'xxxx'; /*** mysql password ***/ $password = 'xxxx'; try { $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->setAttribute(PDO::ERRMODE_EXCEPTION); /*** echo a message saying we have connected ***/ echo 'Connected to database
'; }catch(PDOException $e) { echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message some_logging_function($ex->getMessage()); } ?>[/php]

baffling…


The 500 is the correct page. Now you need to go into the error log and see what the 500 code is for. It could be a number of things that have nothing to do with the code.

i now get this error message (see image below)


and could you please tell me where to find the error log?
thanks


Is there an htaccess file?

Check the root directory/logs

i checked it and here is what i get

"
[28-Dec-2015 07:22:05 UTC] PHP Parse error: syntax error, unexpected ‘$dbh’ (T_VARIABLE) in /home/xxxx/xxxx_xxxx/prac.php on line 99"

what i don’t get is there is not a line 99 in the code.

People don’t understand that when you do a require or include it adds to the file.

Where is that variable declared in other code? Check those lines.

hello all. happy new years eve everyone.
well i have been working on the connection and i finally got the script to post the error message in the script, “An Error Occurred. The Error Is Being Processed!”. next i added the code at the top of the page to determine where the script breaks. this is what the error reads, “Array ( ) Got Here…Connections-order.php”
here is what i’m working with:

[php]

<?php error_reporting(E_ALL); ini_set('display_errors', 1); print_r($_POST); die("Got Here...Connections-order.php"); echo "An Error Occurred. The Error Is Being Processed!"; ?> Untitled Document <?php /*** mysql hostname ***/ $hostname = 'greenthumb.co'; /*** mysql username ***/ $username = 'zzz'; /*** mysql password ***/ $password = 'zzz'; try { $dbh = new PDO("mysql:host=$greenthumb.co;dbname=$order0001", $zzz, $zzz); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->setAttribute(PDO::ERRMODE_EXCEPTION); /*** echo a message saying we have connected ***/ echo 'Connected to database
'; }catch(PDOException $e) { echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message some_logging_function($ex->getMessage()); } ?>

[/php]

the url is eyewasframed.co/prac01.php. looking for a little guidance. thanks, yall.

Happy New Years, Slade !

Now, if you look at that output, it has no posted data. Your page gets to the “GOT HERE” part, but, just
before it, it displays the data in the $_POST’d form. It shows nothing.

Okay, I am confused! What are you trying to do? Are you joking? Okay, first, I will edit out your username
and password. You do not want to post that.

Next, you kill the page before it gets to your connection, so it will never get there.

Lastly, your connection code has the wrong set up. I do not even know where that came from…
Here is an edited version…
[php]

Untitled Document <?php error_reporting(E_ALL); ini_set('display_errors', 1); /*** mysql hostname ***/ $hostname = 'www.greenthumb.com'; /*** mysql username ***/ $username = 'zzzz'; /*** mysql password ***/ $password = 'zzzz'; try { $dbh = new PDO("mysql:host=$hostname; dbname="order0001", $username, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->setAttribute(PDO::ERRMODE_EXCEPTION); // echo a message saying we have connected echo 'Connected to database
'; } catch(PDOException $e) { echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message some_logging_function($ex->getMessage()); } ?>
       SOME TEXT OR HTML ON PAGE 
[/php] This is just loosely done. It is not tested. You have to put in your username, password and place the name of the table you are using into the new-PDO line... (You have "order0001", but, that sounds odd.)

thanks for the advice, ErnieAlex. but the user and password were fictitious. ;D I intend on renaming the table…that is a bit out there. i was just goofin’ around with the database in phpMyAdmin. i guess i should change it to something more reasonable because there is a question about it in the error message. see the image below.

28 $dbh = new PDO(“mysql:host=$hostname;dbname=$order0001”, $username, $password);

40 some_logging_function($ex->getMessage());

but it feels like i’m getting closer.


$order0001,is not defined as a variable.

Get rid of the user error message, you need to see what’s going on.

$e->getMessage()

The dbname= should not have a $ in it if you place the name there. So, $order0001 should be order0001 !

i made the changes that were suggested and this is what i get when i type the url in the address bar:

Notice: Undefined variable: order0001 in /home/xxxx/public_html/prac0.php on line 31

Notice: Undefined variable: ex in /home/xxxx/public_html/prac0.php on line 42

Fatal error: Call to a member function getMessage() on a non-object in /home/xxxx/public_html/prac0.php on line 42

here is the script:
[php]

<?php error_reporting(E_ALL); ini_set('display_errors', 1); /*** mysql hostname ***/ $hostname = 'eyewasframed.co'; /*** mysql username ***/ $username = 'xxxx'; /*** mysql password ***/ $password = 'xxxx'; $dbname = 'order0001'; try { $dbh = new PDO("mysql:host=$hostname;dbname=$order0001", $username, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->setAttribute(PDO::ERRMODE_EXCEPTION); /*** echo a message saying we have connected ***/ echo 'Connected to database
'; }catch(PDOException $e) { ($ex->getMessage()); } ?>

[/php]

i made the changes that were suggested

No you didnt. You still have a dollar sign in the DBname.

Slade? AGAIN, this line:
$dbh = new PDO(“mysql:host=$hostname;dbname=$order0001”, $username, $password);

should be:
$dbh = new PDO(“mysql:host=$hostname;dbname=order0001”, $username, $password);

OR
$dbname = ‘order0001’;
try {
$dbh = new PDO(“mysql:host=$hostname;dbname=$dbname”, $username, $password);

You set up a variable for the db name and called it $dbname. Then you didn’t use it but hard coded the
name to $order0001.

Where are these suggestions coming from? I said $e->getMessage() you put ($ex->getMessage())

Ernie said to hangers the string from being a variable.

my apologies for not being more attentive to my teachers. i think i got it right this time. this is the error message i now get:

"Notice: Undefined variable: ex in /home/ewff/public_html/prac0.php on line 42

Fatal error: Call to a member function getMessage() on a non-object in /home/ewff/public_html/prac0.php on line 42"

here’s the relevant script:

[php]

<?php error_reporting(E_ALL); ini_set('display_errors', 1); /*** mysql hostname ***/ $hostname = 'eyewasframed.co'; /*** mysql username ***/ $username = 'xxxx'; /*** mysql password ***/ $password = 'xxxx'; $dbname = 'order0001'; try { $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->setAttribute(PDO::ERRMODE_EXCEPTION); /*** echo a message saying we have connected ***/ echo 'Connected to database
'; }catch(PDOException $e) { $e->getMessage(); } ?>

[/php]

i hope this is correct…

Something isn’t right.

Are you sure you ran the script you modified? There is no “$ex” now, so I don’t know how that error would appear, and there is no line 42.

instead of this:

$e->getMessage();

Try this:

echo $e->getMessage();

You did nothing with the results…

Sponsor our Newsletter | Privacy Policy | Terms of Service