我一般都是PHP的新手,但我想我已经掌握了它。由于某种原因,数据没有上传到数据库:/
如果您有任何想法是错误的,或者这是一个糟糕的结构,请随时表达您的意见!在此先感谢您的帮助!!
的config.php:
<?php
$database = "LennysPizza"; // the name of the database.
$server = "localhost"; // server to connect to.
$db_user = "root"; // mysql username to access the database with.
$db_pass = "jdish"; // mysql password to access the database with.
$link = mysqli_connect($server, $db_user, $db_pass);
mysqli_select_db($link, $database);
?>
submitorder.php:
<!DOCTYPE html>
<?php
include_once 'functions.php';
include_once 'config.php';
$cheeseburger_quantity = $_POST['cheeseburger_quantity'];
$frenchfries_quantity = $_POST['frenchfries_quantity'];
$chickenfingers_quantity = $_POST['chickenfingers_quantity'];
$chickenfingers_totalprice = 4.75 * $chickenfingers_quantity;
$frenchfries_totalprice = 4.75 * $frenchfries_quantity;
$cheeseburger_totalprice = 4.75 * $cheeseburger_quantity;
$totalprice =
$cheeseburger_totalprice +
$frenchfries_totalprice +
$chickenfingers_totalprice;
if($totalprice <= 0){
header('Location: http://localhost/LennysPizza/index.php');
exit;
} else {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Order Submit</title>
</head>
<body>
<table border ="1">
<tr>
<th>Food:</th>
<th>Quantity:</th>
<th>Price:</th>
</tr>
<tr>
<td>Cheeseburger</td>
<td><?php echo $cheeseburger_quantity; ?></td>
<td><?php echo '$' .$cheeseburger_totalprice;?></td>
</tr>
<tr>
<td>French Fries</td>
<td><?php echo $cheeseburger_quantity; ?></td>
<td><?php echo '$'.$frenchfries_totalprice;?></td>
</tr>
<tr>
<td>Chicken Fingers</td>
<td><?php echo $chickenfingers_quantity; ?></td>
<td><?php echo '$' .$chickenfingers_totalprice; ?></td>
</tr>
<tr>
<td>Total:</td>
<td><?php
echo '$' .$totalprice;
?></td>
</tr>
</table>
<?php
if(isset($_POST['foodaction']) && isset($_POST['customerfirstname']) && isset($_POST['customerlastname']) && isset($_POST['phonenumber'])){
if($_POST['foodaction'] == "Pickup"){
echo "Pickup Order! <br /> Estimated time ready: <b>30 minutes</b> <br /> <br /> <br />
<form method='post' action='sendorder.php'>
<input type='submit' value='Submit Order'>
</form>
"
;
}
if($_POST['foodaction'] == "Delivery"){
if(!empty($_POST['address']) && !empty($_POST['zipcode'])){
echo "Delivery Order! <br />
<b>Address</b>:".$_POST['address']. ", ".$_POST['zipcode']."<br /> <br />
"
;
}else{
echo "You forgot to add your <b>Address</b> and <b>Zip Code</b>!";
}
}
}else{
echo "You didn't specify if you want your order to be <b>Delivered</b> or have it be <b>Picked up</b> <br />";
if(empty($_POST['customerfirstname'])){
echo 'You also have to fill out the <b>First name</b> field.<br />';
}
if(empty($_POST['customerlastname'])){
echo 'You also have to fill out the <b>Last name</b> field.<br />';
}
if(empty($_POST['phonenumber'])){
if($_POST['phonenumber'] )
echo 'You also have to fill out the <b>Phone Number</b> field.<br />';
}
}
}
?>
</body>
</html>
sendorder.php:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Thank you!</title>
</head>
<body>
<?php
// put your code here
include_once 'functions.php';
include_once 'config.php';
$cheeseburger_quantity = isset($_POST['cheeseburger_quantity']);
$frenchfries_quantity = isset($_POST['frenchfries_quantity']);
$chickenfingers_quantity = isset($_POST['chickenfingers_quantity']);
$cheeseburger_comment = isset($_POST['cheeseburger_comment']);
$frenchfries_comment = isset($_POST['frenchfries_comment']);
$chickenfingers_comment = isset($_POST['chickenfingers_comment']);
$customerfirstname = isset($_POST['customerfirstname']);
$customerlastname = isset($_POST['customerlastname']);
$phonenumber = isset($_POST['phonenumber']);
$address = isset($_POST['address']);
$zipcode = isset($_POST['zipcode']);
$insert_delivery = "INSERT INTO orders
(cheeseburger_quantity, cheeseburger_comment, frenchfries_quantity, frenchfries_comment, chickenfingers_quantity, chickenfingers_comment, foodaction, customerfirstname, customerlastname, phonenumber, address, zipcode)
VALUES ('$cheeseburger_quantity', '$cheeseburger_comment', '$frenchfries_quantity', '$frenchfries_comment', '$chickenfingers_quantity', '$chickenfingers_comment', '$customerfirstname', '$customerlastname', '$phonenumber', '$address', $zipcode)";
if(mysqli_query($link, $insert_delivery)){
echo 'Order Submitted!';
}
?>
</body>
</html>
答案 0 :(得分:1)
isset()
是一个布尔测试。你想改变:
$cheeseburger_quantity = isset($_POST['cheeseburger_quantity']);
为:
if (isset($_POST['cheeseburger_quantity'])) {
$cheeseburger_quantity = $_POST['cheeseburger_quantity'];
}
else {
$cheeseburger_quantity = 0;
}