Re: passing data from html to php
Posted: Thu Jan 14, 2016 10:21 am
hello, all. i've been working at this for 2 days trying to discover what i've done wrong. i can't seem to get past the error with regard to the pdo execute statement. it's preventing me from passing the values to the db. it's driving me crazy.
any ideas at all will send me to do more research. thanks all.
for anyone interested to help you have my kudos.
again, this is the php:
and this is the error message:
"Connected to database
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'description' cannot be null' in /home/ewff/public_html/prac0.php:66 Stack trace: #0 /home/ewff/public_html/prac0.php(66): PDOStatement->execute() #1 {main} thrown in /home/ewff/public_html/prac0.php on line 66"
its driving me crazy
, yall.
any ideas at all will send me to do more research. thanks all.
for anyone interested to help you have my kudos.
again, this is the php:
Code: Select all
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 = [];
}
if(empty($errors)) {
// prepare sql and bind parameters
$query = "INSERT INTO details (description, temple, quantity, price)
VALUES (:description, :temple, :quantity, :price)";
}
$stmt = $dbh->prepare($query);
$stmt->bindParam(':description', $_POST['description']);
$stmt->bindParam(':temple', $_POST['temple']);
$stmt->bindParam(':quantity', $_POST['quantity']);
$stmt->bindParam(':price', $_POST['price']);
$stmt->execute();
/*** close the database connection ***/
$dbh = null;
"Connected to database
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'description' cannot be null' in /home/ewff/public_html/prac0.php:66 Stack trace: #0 /home/ewff/public_html/prac0.php(66): PDOStatement->execute() #1 {main} thrown in /home/ewff/public_html/prac0.php on line 66"
its driving me crazy