I am following a tutorial on SQL and learning how to update through PHP, everything seemed to go/work great but when I attempt to "add a customer", in this case, the data updates to the table with an ID, but the customer info that I entered in is blank.
It is as if the data is registering the new insert but not accepting any of the data that is being entered into the form. (Hopefully that makes sense.)
Below is the code for the POST in my "add_customer" page.
<?php
if($_POST){
//Get Variables from post array
$first_name = mysqli_real_escape_string($_POST['first_name']);
$last_name = mysqli_real_escape_string($_POST['last_name']);
$email = mysqli_real_escape_string($_POST['email']);
$password = mysqli_real_escape_string(md5($_POST['password']));
$address = mysqli_real_escape_string($_POST['address']);
$address2 = mysqli_real_escape_string($_POST['address2']);
$city = mysqli_real_escape_string($_POST['city']);
$state = mysqli_real_escape_string($_POST['state']);
$zipcode = mysqli_real_escape_string($_POST['zipcode']);
//Create Customer query
$query ="INSERT INTO customers (first_name,last_name,email,password)
VALUES ('$first_name','$last_name','$email','$password')";
//Run query
$mysqli->query($query);
//Create address query
$query ="INSERT INTO customer_addresses (customer,address,address2,city,state,zipcode)
VALUES ('$mysqli->insert_id','$address','$address2','$city','$state','$zipcode')";
//Run query
$mysqli->query($query);
$msg='Customer Added';
header('Location: index.php?msg='.urlencode($msg).'');
exit;
}
?>
I am not going to post all the code for the form, as most of it is the same minus the type and placeholder, but the gist of the form code is as follows
<form role="form" method="post" action="add_customer.php">
<div class="form-group">
<label>First Name</label>
<input name="first_name" type="text" class="form-control" placeholder="Enter First Name">
</div>
Unfortunately I cannot add the image of the Added page(not enough rep yet), but the page will come up with a new line, all blank, but showing the edit button at the end. So something is going through the database enough to create a new id for the inputted data, but the data itself is not being stored to the database.
All help is appreciated! Please let me know if ANY additional info is needed to help clear this up.
This has been resolved. I was misunderstanding the mysqli string and did not have my connection variable.*