This is a progression from last night's question, now I need to get the value from $total
in my if/else statement and insert it into my database. $count['NumRows']
for price and $total
for total_all...
I've read about changing the value to array by using implode
, but the problem is still there, my database still won't store the value... because I don't know why and I need help...
<?php
if (isset($_POST['submit'])) {
$names = $_POST['names'];
$phones = $_POST['telno'];
$modelname = $_POST['modelname'];
$rentaldate = $_POST['rentaldate'];
$numday = $_POST['numday'];
$sql = "INSERT INTO carbook (name, tel_no, model_name, rental_date, return_date, no_of_days) VALUES ('$names', '$phones', '$modelname', '$rentaldate', '$returndate', '$numday')";
if ($conn->query($sql) == true) {
echo "Name: $names";
echo "<br/>Phones: $phones";
echo "<br/>Car Name: $modelname";
echo "<br/>Rental Date: $rentaldate";
echo "<br/>Return Date: $returndate";
echo "<br/>No Of Days: $numday";
echo "<br/>";
} else {
echo "Error: $sql<br>$conn->error";
}
if ($modelname && $numday) {
if ($modelname = 'Jetta') {
$countrows = 'SELECT price_day AS NumRows FROM carlist WHERE carBookId = 1';
$result = $conn->query($countrows);
$count = $result->fetch_assoc();
$total = $count['NumRows'] * $numday;
$total = number_format($total, 2);
echo 'Price per day: RM<b>' . $count['NumRows'] . '</b>.<br/>';
echo 'Total Price: RM<b>' . $total . '</b>.';
$sql = "INSERT INTO carbook (price, total_all) VALUES ('$total', '$countrows')";
There's no error, but the database didn't recognize the value, and it still inserts 0 in my table.
edited this is my table structure
table structure