sladepowers Posted January 9, 2016 Share Posted January 9, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300239-passing-html-values-to-php/ Share on other sites More sharing options...
Barand Posted January 9, 2016 Share Posted January 9, 2016 $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. Quote Link to comment https://forums.phpfreaks.com/topic/300239-passing-html-values-to-php/#findComment-1529307 Share on other sites More sharing options...
Jacques1 Posted January 9, 2016 Share Posted January 9, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300239-passing-html-values-to-php/#findComment-1529313 Share on other sites More sharing options...
benanamen Posted January 9, 2016 Share Posted January 9, 2016 FYI Experts, slade has run up a thread with 158 posts on basically the same matter on another forum frustrating every expert programmer there and has apparently decided to come here. Fasten your seatbelts for this ride. Quote Link to comment https://forums.phpfreaks.com/topic/300239-passing-html-values-to-php/#findComment-1529323 Share on other sites More sharing options...
mac_gyver Posted January 9, 2016 Share Posted January 9, 2016 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/300239-passing-html-values-to-php/#findComment-1529327 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.