如何连接数据库它一直说
致命错误:未捕获的错误:在C中没有找到类“msqli”:#0 {main}在C:\xampp\htdocs\5Dec2021\Order.php第90行中抛出。当我转到http://localhost/5Dec2021/Menu.html时,它工作正常。我可以单击按钮并回答文本框Here,但在我提交后,它变成This。
这是我的HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<form method="post" action="Order.php">
<table border="1" style="width: 100%">
<tr>
<th colspan="2" style="height: 25px">Pizza Shop 2.0</th>
</tr>
<tr>
<td style="width: 310px">Name:</td>
<td>
<input name="Text1" id="Name" type="text" style="width: 299px" /></td>
</tr>
<tr>
<td style="width: 310px">Pizza Topping:</td>
<td><input name="Checkbox1[]" type="checkbox" id="supreme"value="Supreme" />Supreme<br>
<input name="Checkbox1[]" type="checkbox" id="vegetarian" value="Vegetarian" />Vegetarian<br>
<input name="Checkbox1[]" type="checkbox" id="haiwaian" value="Haiwaian" />Haiwaian
</td>
</tr>
<tr>
<td style="width: 310px">Pizza Sauce:</td>
<td><select name="Select1" id="dropdown" style="width: 296px">
<option selected="selected" value="0">-</option>
<option value="Ketchup">Ketchup</option>
<option value="Bolognese">Bolognese</option>
<option value="CheeseSpread">Cheese Spread</option>
</select></td>
</tr>
<tr>
<td style="height: 23px; width: 310px;">Optional Extra:</td>
<td style="height: 23px">
<input name="Checkbox2[]" type="checkbox" id="extra" value="Extra cheese" />Extra Cheese <br>
<input name="Checkbox2[]" type="checkbox" id="gluten" value="Gluten free base" />Gluten Free Base
</td>
</tr>
<tr>
<td style="width: 310px" colspan="2">Delivery Instruction:<br>
<textarea name="TextArea1" style="width: 608px; height: 127px"></textarea></td>
</tr>
<tr>
<td style="width: 310px" colspan="2"><input name="submit" type="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
"这是我的PHP"
<?php
//variable declaration
$name=$_POST['Text1'];
$p=0;
$p2=0;
if (isset($_POST['Checkbox1']))
{
$top=$_POST['Checkbox1'];
$c=count($top);
for ($i=0; $i<$c;$i++)
{
If($top[$i]=="Supreme")
{
$p=$p+15;
}
If($top[$i]=="Vegetarian")
{
$p=$p+11;
}
If($top[$i]=="Haiwaian")
{
$p=$p+12;
}
}
}
if (isset($_POST['Select1']))
{
$sauce=$_POST['Select1'];
If($sauce=="0")
{
$p2=$p2+0;
}
If($sauce=="Ketchup")
{
$p2=$p2+4;
}
If($sauce=="Bolognese")
{
$p2=$p2+3;
}
If($sauce=="CheeseSpread")
{
$p2=$p2+5;
}
}
$p3=0;
if (isset($_POST['Checkbox2']))
{
$extra=$_POST['Checkbox2'];
$c=count($extra);
for ($i=0; $i<$c; $i++)
{
If($extra[$i]=="Extra cheese")
{
$p3=$p3+10;
}
If($extra[$i]=="Gluten free base")
{
$p3=$p3+5;
}
}
}
$delivery =$_POST['TextArea1'];
$total=0;
$total=$p+$p2+$p3;
$top=implode(" ",$_POST['Checkbox1']); // HAVE TO IMPLODE IF CAN BE MULTIPLE VALUES.
$extra=implode(" ",$_POST['Checkbox2']);
date_default_timezone_set("Asia/Kuala_Lumpur");
$date=date("d-m-Y H:i:sa");
echo "<h1>Billing statement</h1>";
echo "<br>";
echo "Hi ".$name;
echo "<br>";
echo "Total bill RM: ".$total;
//database configuration (pizzatime is the folder of the table name)
$con= new msqli("localhost","root","","pizzatime");
//is the connection working? connection error
if($con->connect_error)
{
die("Warning!Connection Failed!".$con->connect_error);
}
//if connection is ok (orderpizza is the table name, and INSERT INTO IS THE COLUMN NAMES WHILE THE VALUES ARE THE CONTAINERS OF THE BUTTONS/CHECKBOX/...
$database="INSERT INTO orderpizza(Time,Name,Top,Sauce,Extra,Delivery,Total) VALUES
('$date','$name','$top','$sauce','$extra','$delivery','$total')";
if($con->query($database)===TRUE)
{
echo "<br>";
echo "<alert>'Successfully save into the database'</alert>;";
}
else
{
echo "Error".$con->connect_error;
}
$con->close();
?>
1条答案
按热度按时间u7up0aaq1#
我不得不将Xampp端口更改为4306,因为它不工作,所以我必须在localhost旁边添加:4306