For an assignment, I am using PHP to add a new customer to mySQL database. I am getting this error message:
Notice: Undefined index: name in C:\xampp\htdocs\bookorama\insert_customer.php on line 10
Notice: Undefined index: address in C:\xampp\htdocs\bookorama\insert_customer.php on line 11
Notice: Use of undefined constant customerid - assumed ‘customerid’ in C:\xampp\htdocs\bookorama\insert_customer.php on line 14
You have not entered all the required details.
Please go back and try again.
[php]new_customer.html
Book-O-Rama - New Customer EntryBook-O-Rama - New Customer Entry
Name | |
Address | |
City | |
insert_customer.php
Book-O-Rama Customer Entry ResultsBook-O-Rama Book Customer Results
<?php // create short variable names $customerid=$_POST['customerid']; $name=$_POST['name']; $address=$_POST['address']; $city=$_POST['city']; if (!customerid || !$name || !$address || !$city) { echo "You have not entered all the required details." ."Please go back and try again."; exit; } if (!get_magic_quotes_gpc()) { $customerid = addslashes($customerid); $name = addslashes($name); $address = addslashes($address); $city = addslashes($city); } @ $db = new mysqli('localhost', 'root', 'pac3', 'books'); if (mysqli_connect_errno()) { echo "Error: Could not connect to database. Please try again later."; exit; } $query = "insert into customers values ('".customerid."', '".$name."', '".$address."', '".$city."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." customers inserted into database."; } else { echo "An error has occurred. The item was not added."; } $db->close(); ?> [/php]