collecting data from html template for php script

well, i know its been a while but i’ve seriously been studying (and trying to have a life…heck, this IS my life :D).
i’ve made a few changes and need a better pair of eyes than mine to see how it looks. well, here goes.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<?php

/*** mysql hostname ***/
$hostname = 'xxxx.co';

/*** mysql username ***/
$username = 'xxx';

/*** mysql password ***/
$password = 'xxxx';


try {
<?php
$db = new PDO('mysql:host=localhost;dbname=order001;charset=utf8', 'username', 'password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
echo 'Connected to database<br />';


catch(PDOException $ex) {
    echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message
    some_logging_function($ex->getMessage());


?>

<body>

<?php
// define variables and set to empty values
$item = $temple = $quantity = $price = $promotional = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $item = ordertest01($_POST["item"]);
   $temple = ordertest01($_POST["temple"]);
   $quantity = ordertest01($_POST["quantity"]);
   $price = ordertest01($_POST["price"]);
   $promotional = ordertest01($_POST["promotional"]);
   
}

function ordertest01($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
?>


<?php

$item = htmlspecialchars($_POST['Item']);
$temple = htmlspecialchars($_POST['Temple']);
$quantity = htmlspecialchars($_POST['Quantity']);
$price = htmlspecialchars($_POST['Price']);
$promotional = htmlspecialchars( $_POST['Promotional']);

              $result = $db->exec("INSERT INTO orders0001(Item, Temple, Quantity, Price, Promotional) VAULES (':item', ':temple', 
':quantity', ':price', ':promotional')";

$stmt->bindParam(':item', $item);
$stmt->bindParam(':temple', $temple);
$stmt->bindParam(':quantity', $quantity);
$stmt->bindParam(':price', $price);
$stmt->bindParam(':promotional', $promotional);
		  
header( "Location: http://www..com/.....html" )


/*** close the database connection ***/
$dbh = null;

?>
</body>
</html>

any feedback is most welcomed. thanks

Wow! You have jumped up a level from the first posts… So, you have moved up in the PHP coding…

So, I would suggest that you move your functions to the top of your PHP code. Most programmers stash
all of their functions into a separate file and include them. Either way does work. But, you test to see if the
page was posted and then stick in a function and then go back to the work of the posted code…

So, moving the functions above the check for posted code would mean you don’t have to stop the flow of
that section. With the function out of the way, after you test for the post, you can go right into the check
for special characters…

Now, once you fix that, and test it let us know where you are stuck. I think you are coming along very
well. Do not worry how long it takes! Learning code is a time issue. We have all been thru that!

So, think out your “flow” of your code and come back when you need further help! Nice going!

hello again. i’m stuck. i cannot test the php. i get a server error message. i can connect to the db and it’s tables via dreamweaver. what am i doing wrong?

here is my revised script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<?php

/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'xxxx';

/*** mysql password ***/
$password = 'xxxx';


try {
<?php
$db = new PDO('mysql:host=localhost;dbname=order0001;charset=utf8', 'username', 'password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
echo 'Connected to database<br />';



catch(PDOException $ex) {
    echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message
    some_logging_function($ex->getMessage());
	
?>

<body>

<?php
// define variables and set to empty values
$item = $temple = $quantity = $price = $promotional = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $item = ordertest01($_POST["item"]);
   $temple = ordertest01($_POST["temple"]);
   $quantity = ordertest01($_POST["quantity"]);
   $price = ordertest01($_POST["price"]);
   $promotional = ordertest01($_POST["promotional"]);
   
}

function ordertest01($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
?>




<?php

$item = htmlspecialchars($_POST['Item']);
$temple = htmlspecialchars($_POST['Temple']);
$quantity = htmlspecialchars($_POST['Quantity']);
$price = htmlspecialchars($_POST['Price']);
$promotional = htmlspecialchars( $_POST['Promotional']);


$stmt->bindParam(':item', $item);
$stmt->bindParam(':temple', $temple);
$stmt->bindParam(':quantity', $quantity);
$stmt->bindParam(':price', $price);
$stmt->bindParam(':promotional', $promotional);
		  
		  
		  $result = $db->exec("INSERT INTO order0001(Item, Temple, Quantity, Price, Promotional) VAULES (':item', ':temple', 
':quantity', ':price', ':promotional')";		  
		  
		  
header( "Location: http://www..com/.....html" )




/*** close the database connection ***/
$dbh = null;



?>



</body>
</html>

i guess i'm getting closer....

this is the specific error message:

“The website encountered an error while retrieving http://xxxx.com/testpage.php. It may be down for maintenance or configured incorrectly.”

Lines 21, 58, and 63.

changed it to this and same results:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<?php

/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'xxx';

/*** mysql password ***/
$password = 'xxxx';


try {
$db = new PDO('mysql:host=localhost;dbname=order0001;charset=utf8', 'username', 'password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
echo 'Connected to database<br />';



catch(PDOException $ex) {
    echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message
    some_logging_function($ex->getMessage());
	
?>

<body>

<?php
// define variables and set to empty values
$item = $temple = $quantity = $price = $promotional = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $item = ordertest01($_POST["item"]);
   $temple = ordertest01($_POST["temple"]);
   $quantity = ordertest01($_POST["quantity"]);
   $price = ordertest01($_POST["price"]);
   $promotional = ordertest01($_POST["promotional"]);
   
}

function ordertest01($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}





$item = htmlspecialchars($_POST['Item']);
$temple = htmlspecialchars($_POST['Temple']);
$quantity = htmlspecialchars($_POST['Quantity']);
$price = htmlspecialchars($_POST['Price']);
$promotional = htmlspecialchars( $_POST['Promotional']);


$stmt->bindParam(':item', $item);
$stmt->bindParam(':temple', $temple);
$stmt->bindParam(':quantity', $quantity);
$stmt->bindParam(':price', $price);
$stmt->bindParam(':promotional', $promotional);
		  
		  
		  $result = $db->exec("INSERT INTO order0001(Item, Temple, Quantity, Price, Promotional) VAULES (':item', ':temple', 
':quantity', ':price', ':promotional')";		  
		  
		  
header( "Location: http://www..com/.....html" )




/*** close the database connection ***/
$dbh = null;



?>



</body>
</html>

Your try catch statement is missing some brackets.

If you are developing on your local machine, turn error reporting on in your php.ini file; if this is on a plublic host (temporarily use )
[php]
ini_set(‘display_errors’, 1);
error_reporting(E_ALL);[/php]

Or check the error log to see what is going on.

when i made a few changes and the error message changed (please see img attached):

i don’t know what i did to create the change but i guess a different result that at least points to the url is progress because the other error message read that there may have been a issue of misconfiguration.


Well, that is saying that you are not going to the correct page to display.

So, if your server is hosted, then it will be like: www.yourdomain.com
and, to access your test page, it is www.yourdomain.com/testpage01.php

If you are not hosted and running on your computer, you would go to it with your local server’s address,
then testpage01.php. SO, if you are running WAMP or XAMP, you have a control panel down by the clock
that is your server and you can open your local host there and then open the testpage01.php.

ANY 404 on a webpage in a browser means that you are not pointing to the file correctly.

hello, again. i’m wondering about the option to choose temples when using the shopping cart. there are 5 temples to choose from. How would i pass one of those values to php so i can insert it into the db?

i know its getting late out where y’all at. thanks for your time.

Can you be a bit more specific?

Inserting data into a database is a simple task. What are you actually wanting to know?

Technically, you have 5 templates. A table that stores the names, id’s, hell even the template itself in a row. You can then insert the id of a specific template to a specific user and know exactly what they chose. But, it doesn’t sound like you know exactly what you want yet.

hello, astonecipher.

the shopping cart i am working with is here: http://solutionm3.com/ordertest.html
i don’t know how to work the id’s for each value. the back side of the shopping cart is kinda obscure. i can’t identify the id’s. i’m thinking those id’s have a different name than the one’s i chose:
$item, $temple, $quantity, $price, $promotional

i think i need to tie my script into the variables at the backside of the cart. point me in the right direction…thanks a heap.

also i wanted to know why i get no echo from this statement:

[php]echo ‘Connected to database
’;[/php]

the message doesn’t display in the page. Any insights?

i must have moved something because i can’t get the connection right again. i gotta check my paths. i think the mix up is i was working with the localhost on my computer and working it through my hosting service (1&1). i messed up somewhere. gotta track it down.

If you are working local and remote ( two different databases/ connections ) you may want to check the IP and if it is local use one connection if not use another.

what’s throwing me is i have 2 scripts exactly the same. when i run the 1st file through dreamweaver’s preview in browswer i get a error 500 message. with the other file i get “404 file not found”. it must be something i don’t see. here is the script:

[php]

<?php /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'xxxx'; /*** mysql password ***/ $password = 'xxxx'; try { $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->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]

what gives? i’m baffled.

Dreamweaver is bad to use in general.

Are they both on your local machine or is one hosted and the other local?

i run everything through dreamweaver and upload my finished docs to my hosted server (1&1). i run mysql, phpadmin and everything directly from the 1&1 server.

To fix dreamweaver issues, go to your programs manager, right click on dreamweaver and select uninstall.

why does dreamweaver have such a bad rap?

Sponsor our Newsletter | Privacy Policy | Terms of Service