Jump to content

Recommended Posts

can anyone help me and tell me what's wrong with this script.i haven't had to write script for a while. since before PDO.  i've been working at and just can't seem to get it. any help would be much appreciated. 

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

error_reporting(E_ALL);
    ini_set('display_errors', 1);


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

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

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


try {
    $dbh = new PDO("mysql:host=$hostname;dbname=new_order", $username, $password);
	

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
echo 'Connected to database<br />';

}catch(PDOException $e) {
     echo $e->getMessage();
}
?>

<body>


<?php


if ($_SERVER["REQUEST_METHOD"] == "POST")

$errors = array();

    if(empty($errors))




// prepare sql and bind parameters
$stmt = $dbh->prepare("INSERT INTO new_order (item, temple, quantity, price) VALUES(?,?,?,?)");
$stmt->bind_param("ssss", $item, $temple, $quantity, $price);
$stmt->execute(); 



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

?>

</body>
</html>

the attached image shows the error message when processing this script. any guidance will be accepted and implemented. thanks, all.

Link to comment
https://forums.phpfreaks.com/topic/300239-passing-html-values-to-php/
Share on other sites

 

$stmt->bind_param("ssss", $item, $temple, $quantity, $price);

 

It looks like your coding is is from the 1990's when register_globals were used. Those param values need to come from the $_POST array.

 

And if your quantity and price columns really are string types then you need to redesign your table.

A PDO statement doesn't have a bind_param() method. That's code for the MySQLi extension which is an entirely different database interface not related to PDO in any way.

 

It looks like you've randomly copied and pasted code from different sources. This doesn't work. You need to pick one interface (PDO is generally preferable) and then learn how to use it. The PHP manual is a good place to start. There's also a well-written tutorial on hashphp.org.

then, i know of a third help forum, with two shorter threads for this problem, filled with replies listing what's wrong with the current randomly thrown together code, and what the code needs to be doing, with a working pdo example that matches the form data, that could have been followed, but wasn't.

 

nor was the advice that was given that the OP needed to actually learn the meaning of what he is doing in order to successfully write any code.

 

resulting in no one continuing to post replies.

 

if the OP revisits this thread, you cannot program by mimicking things you have seen posted on the web. randomly putting pieces of code together will take an infinite amount of time to come up with code that does something. repeatedly asking someone else to look at your randomly changing 'moving target' of code will quickly loose the free help, because no one likes to see their volunteered time go to waste.

 

you need to first go and learn the basics of the php language, so that you will know what an if(){} conditional statement, that encloses multiple statements, even looks like.

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.