所以我正在尝试创建一个HTML / PHP代码,要求您订购糖果棒(火星,士力架,银河系),然后列出订单的收据,成本,总成本等等。我做了所有这些,现在我想将所有值存储到MySQL数据库中,当点击订单时我想列出从数据库中生成的每个订单。我正在努力,但无法理解。它立刻给我错误,它无法连接到MySQL数据库,我使用WAMP localhost,我创建了数据库和用户和所有权限,尝试了一百次,但没有。不知道我做错了什么。
错误如下:
警告:mysqli_connect():在第34行的C:\ wamp \ www \ MAKEUP2 \ Q1 \ order.php中调用堆栈#时间内存函数位置1 0.0010 143072 {main}().. \ order.php:0 2 0.0010 144488 mysqli_connect().. \ order.php:34连接失败:Accèsrefusépourl'utilisateur:'revetinja'@'@ localhost'(mot de passe:OUI)
这就是我到目前为止所做的......
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<title>Candy order</title>
</head>
<body>
<p> </p>
<?php
$mars = $_POST['mars'];
$snickers = $_POST['snickers'];
$milkyway = $_POST['milkyway'];
$address = $_POST['address'];
$marsprice = 1.5;
$snickersprice = 1.7;
$milkywayprice = 1.8;
$totalquantity = $mars + $snickers + $milkyway;
$totalcost = $marsprice * $mars + $snickersprice * $snickers + $milkywayprice * $milkyway;
$marscost = $mars * $marsprice;
$milkycost = $milkyway * $milkywayprice;
$snickerscost = $snickers * $snickersprice;
$servername = "localhost";
$username = "revetinja";
$password = "wrong123";
$dbname = "makeup2";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO orders (item, cost, quantity, total, address)
VALUES ('Mars', '$marsprice', '$mars', '$marscost', '$address')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<div class="container">
<h2>Thank you!</h2>
<p>Your orders for: </p>
<table border-bottom 1px solid grey;>
<tr>
<th width=150 align="center">Item<br> </td>
<th width=100 align="center">Cost<br> </td>
<th width=100 align="center">Quantity<br> </td>
<th align="center" width=100>Total cost<br> </td>
<tr>
<td>Mars</td>
<td align="left"><?php echo $marsprice . ' KM'; ?></td>
<td align="left"><?php echo $mars; ?></td>
<td align="left"><?php echo $mars * $marsprice . ' KM'; ?></td>
</tr>
<tr>
<td>Snickers</td>
<td align="left"><?php echo $snickersprice . ' KM'; ?></td>
<td align="left"><?php echo $snickers; ?></td>
<td align="left"><?php echo $snickers * $snickersprice . ' KM'; ?></td>
</tr>
<tr>
<td>Milky ways</td>
<td align="left"><?php echo $milkywayprice. ' KM'; ?></td>
<td align="left"><?php echo $milkyway; ?></td>
<td align="left"><?php echo $milkyway * $milkywayprice. ' KM'; ?></td>
</tr>
<br/>
<tr>
<td><strong>Total</td>
<td align="left"></td>
<td align="left"><strong><?php echo $totalquantity; ?></td>
<td align="left"><strong><?php echo $totalcost . ' KM'; ?></td>
</tr>
<td>Delivery on:
<td colspan="6"><?php echo $address; ?></td>
</tr>
</table>
<p>were processed.</p>
<a href="order.html" class="btn btn-default" align="center">Go back to orders</a>
</div>
</body>
</html>