your help is required on what should be very straightforward.
I have a modal form in Bootstrap that collects Customer info and I wish to save this information in a MYSQL database.
I'm not getting any errors but the values are not inserting into the database table. PDO connection seems because autoincrement values in the table are being added on submit (but not the values from the form).
Here's the modal form code:
<!-- Modal Insert Form -->
<div class="modal fade" id="insert" tabindex="-1" role="dialog" aria-labelledby="insert" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
<h4 class="modal-title custom_align" id="Heading">Add New Customer Detail</h4>
</div>
<form class="form-horizontal" method="post" action="customers_add.php">
<div class="modal-body">
<div class="row">
<div class="col-xs-6">
<input name="firstname" id="firstname" type="text" class="form-control" placeholder="First Name">
</div>
<div class="col-xs-6">
<input type="text" class="form-control" placeholder="Last Name">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-12">
<input type="text" class="form-control" name="company" placeholder="Company">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-12">
<input type="text" class="form-control" name="address1" placeholder="Address Line 1">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-12">
<input type="text" class="form-control" name="address2" placeholder="Address Line 2">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-4">
<input type="text" class="form-control" name="town" placeholder="Town">
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="county" placeholder="County">
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name ="postcode" placeholder="Post Code">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-6">
<input type="text" class="form-control" name="telephone1" placeholder="Telephone 1">
</div>
<div class="col-xs-6">
<input type="text" class="form-control" name="telephone2" placeholder="Telephone 2">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-6">
<input type="text" class="form-control" name="website" placeholder="Website">
</div>
<div class="col-xs-6">
<input type="text" class="form-control" name="referredby" placeholder="Referred By">
</div>
</div>
<br>
<div class="form-group">
<div class="col-xs-12">
<textarea rows="2" class="form-control" name="dietaryreq" placeholder="Dietary Requirements"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<textarea rows="2" class="form-control" name="notes" placeholder="Notes"></textarea>
</div>
</div>
</div>
<div class="modal-footer ">
<button type="submit" name="submit" id="submit" class="btn btn-success btn-lg" style="width: 100%;" value="Add Customer">
<span class="glyphicon glyphicon-ok-sign"></span>
Add New Customer
</button>
</div>
</form>
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div>
... and here's the php that should process the form values into the mysql database:
<?php
include('config.php');
// check if variable is set and Add Customer Button pressed.
if(isset($_POST["submit"])=="Add Customer")
{
// Define Variables
$userref = $_SESSION['user']['User_Ref'];
$customerref = $POST[customerref];
$firstname = $POST[firstname];
$lastname = $POST[lastname];
$company = $POST[company];
$addressline1 = $POST[addressline1];
$addressline2 = $POST[addressline2];
$town = $POST[town];
$county = $POST[county];
$postcode = $POST[postcode];
$telephone1 = $POST[telephone1];
$telephone2 = $POST[telephone2];
$emailaddress = $POST[emailaddress];
$website = $POST[website];
$referredby = $POST[referredby];
$dietaryreq = $POST[dietaryreq];
$notes = $POST[notes];
// Prepare SQL Query
$STM = $db->prepare("INSERT INTO Customers(User_Ref, Customer_Ref, First_Name, Last_Name, Company, Address_Line_1, Address_Line_2, Town, County, Post_Code, Telephone_1, Telephone_2, Email_Address, Website, Referred_By, Dietary_Req, Notes) VALUES (:userref,:customerref,:firstname,:lastname,:company,:addressline1,:addressline2,:town,:county,:postcode,:telephone1,:telephone2,:emailaddress,:website,:referredby,:dietaryreq,:notes)");
// Bind parameters, Named parameters always start with colon(:)
$STM->bindParam(':userref',$userref);
$STM->bindParam(':customerref',$customerref);
$STM->bindParam(':firstname',$firstname);
$STM->bindParam(':lastname',$lastname);
$STM->bindParam(':company',$company);
$STM->bindParam(':addressline1',$addressline1);
$STM->bindParam(':addressline2',$addressline2);
$STM->bindParam(':town',$town);
$STM->bindParam(':county',$county);
$STM->bindParam(':postcode',$postcode);
$STM->bindParam(':telephone1',$telephone1);
$STM->bindParam(':telephone2',$telephone2);
$STM->bindParam(':emailaddress',$emailaddress);
$STM->bindParam(':website',$website);
$STM->bindParam(':referredby',$referredby);
$STM->bindParam(':dietaryreq',$dietaryreq);
$STM->bindParam(':notes',$notes);
// Execute prepared statement
$STM->execute();
// Redirecting it to other page where we will show success message.
header("location:customers.php");
}
?>
Hopefully a simple thing to fix, thanks