I am getting a white screen of death with no errors anywhere. var_dump() does not seem to help.
<?php
$host = "localhost";
$user = "custdb";
$pass = "ms";
$db = "accounting";
$odb = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);
//insert customer
if (isset($_POST['name'])) {
$cust_name = $_POST['cust_name'];
$cust_addr = $_POST['cust_addr'];
$cust_phone = $_POST['cust_phone'];
$cust_email = $_POST['cust_email'];
$q = "INSERT INTO customer (cust_name,cust_addr,cust_phone,cust_email)
SELECT * FROM (SELECT cust_name) as tmp WHERE NOT EXISTS (SELECT cust_name FROM customer WHERE cust_name = '1');";
$query = $odb->prepare($q);
var_dump($cust_name);
$results = $query->execute(array(
":cust_name" => $cust_name,
":cust_addr" => $cust_addr,
":cust_phone" => $cust_phone,
":cust_email" => $cust_email,
));
var_dump($cust_addr);
var_dump($results);
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Contacts Database </title>
</head>
<body>
<form methd="post" action"">
Name: <input type="text" id="cust_name" /><br />
Address: <input type="text" id="cust_addr" /><br />
Phone: <input type="text" id="cust_phone" /><br />
Email: <input type="text" id="cust_email" /><br />
<input type ="submit" value"add" />
<form>
<?php
$query = "SELECT * FROM customer";
$result = $odb->query($query);
if($result->rowCount() > 0) {
foreach($result as $item) {
echo($item['cust_name'] .",". $item['cust_addr'] .",". $item['cust_phone'] .",". $item['cust_email']."<br />\n");
}
}
?>
****************** output *******************
Name: Address: Phone: Email: bob,666 bo rd,2124442222,bo@bo.com
https://i.stack.imgur.com/Kn9lE.png
enter code here
************ sql cli *******************
mysql> INSERT INTO customer (cust_name,cust_addr,cust_phone,cust_email )
-> SELECT * FROM (SELECT 'bob', '666 bo rd','2124442222','bo\@bo.com') AS tmp
-> WHERE NOT EXISTS (
-> SELECT cust_name FROM customer WHERE cust_name='bob')
-> LIMIT 1;
Query OK, 1 row affected, 1 warning (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from customer; +----+-----------+-----------+------------+------------+
| id | cust_name | cust_addr | cust_phone | cust_email |
+----+-----------+-----------+------------+------------+
| 1 | bob | 666 bo rd | 2124442222 | bo@bo.com |
+----+-----------+-----------+------------+------------+
1 row in set (0.00 sec)