I'm trying to have it where multiple orders from the same user, but when I go to create another order with the same first name as the other order it comes up with an error, But if you change the first name to something that is admin like admin1 it will store the order in the MySQL its only when its two different names :
Here is the error:
Error: INSERT INTO orders (userid,username,firstname, lastname, orderdate , address, email, tires, oil, sparks, detailkit, total, tordered, phonenumber, storeid) VALUES ('101','bigfella','admin', '' ,'18:27, 29th January 2018', '', '', '', '','', '' , '0', '0', '','Choose...' ) Duplicate entry 'admin' for key 'name'
Here is the Order.php form
<form action="process.php" method="post">
<div class="form-row">
<div class="form-group col-md-6">
<label class="cblack" for="firstname">First Name:</label>
<input type="text" class="form-control" id="firstname" name="firstname" placeholder="First Name">
</div>
<div class="form-group col-md-6">
<label class="cblack" for="lastname">Last Name:</label>
<input type="text" class="form-control" id="lastname" name="lastname" placeholder=" Last Name">
</div>
<div class="form-group col-md-6">
<label class="cblack" for="email">Email Address:</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
</div>
<div class="form-group col-md-6">
<label class="cblack" for="phonenumber">Phone Number:</label>
<input type="text" class="form-control" id="phonenumber" name="phonenumber" placeholder="503-555-0000">
</div>
</div>
<div class="form-group">
<label class="cblack" for="address">Shipping Address:</label>
<input type="text" class="form-control" id="address" name="address" placeholder="455 Your Address Here ">
</div>
<div class="form-row">
<div class="form-group col-md-2">
<label class="cblack" for="tires">Tires:</label>
<input type="text" class="form-control" name="tireqty" id="tires" placeholder="0">
</div>
<div class="form-group col-md-2">
<label class="cblack" for="oil">Oil:</label>
<input type="text" class="form-control" name="oilqty" id="oil" placeholder="0">
</div>
<div class="form-group col-md-2">
<label class="cblack" for="sparks">Spark Plugs:</label>
<input type="text" class="form-control" name="sparkqty" id="sparks" placeholder="0">
</div>
<div class="form-group col-md-2">
<label class="cblack" for="detailkit">Detailing Kits:</label>
<input type="text" class="form-control" name="detailkit" id="detailkit" placeholder="0">
</div>
</div>
</div>
<button type="submit" id="submit" name="submit" class="btn btn-primary">Submit Your Order.</button>
</form>
Process.php (Stores into the Database)
$phonenumber = $_POST['phonenumber'];
$detailkit = $_POST['detailkit'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$totalqty = $tireqty + $oilqty + $sparkqty + $detailkit;
$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);
define('detailkit', 50);
$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $detailkit * detailkit
+ $sparkqty * SPARKPRICE;
$taxrate = 0.00; // local sales tax is 10%
$totalamount = $totalamount * (1 + $taxrate);
//Code Will Insert into database Table.
$servername = "localhost";
$username = "xxxxxx";
$password = 'xxxxxx';
$dbname = "xxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST['submit'])) { //On Submit Run below code :) For Automotive and then insert into database - AB
$address = $_POST['address'];
$firstname = $_POST['firstname'];
$lastname= $_POST['lastname'];
$email = $_POST['email'];
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$total = $_POST['total'];
$phonenumber = $_POST['phonenumber'];
$detailkit = $_POST['detailkit'];
$userid = $_SESSION['user']['id'];
$username = $_SESSION['user']['username'];
$name = $_POST['storeaddress'];
foreach ($name as $storeid){
}
$totalqty = $tireqty + $oilqty + $sparkqty + $detailkit;
//$totalordered = $_POST['totalordered'];
$sql = "INSERT INTO orders (userid,username,firstname, lastname, orderdate , address, email, tires, oil, sparks, detailkit, total, tordered, phonenumber, storeid)
VALUES ('$userid','$username','$firstname', '$lastname' ,'$date', '$address', '$email', '$tireqty', '$oilqty','$sparkqty', '$detailkit' , '$totalamount', '$totalqty', '$phonenumber','$storeid' )";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
Any Ideas on why it's not wanting to store multiple users orders with the same first name? And how I might be able to fix this issue?
Database: Heres the Database
Info Stored in Database: Info store in database
I ran Describe orders in mysql heres the output