gpt4 book ai didi

php - 使用xampp的php mysql连接出错

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:39 25 4
gpt4 key购买 nike

我正在尝试使用 Xampp 将使用 PHP 表单的 HTML 页面连接到 MySQL 数据库。 HTML 页面工作正常,但只要我按下提交按钮,就会出现一个具有不同字符的页面,有人可以帮助解决这个问题吗?![php 页面][1]

HTML代码:

    <html>
<body>
<body bgcolor="black">
<font color="white">

<form action="a.php" method="post">

<center>
<h1><font color = "gold"><marquee>Welcome to online bus booking!!!</h1></marquee> </font color>
<h3>
First Name:<br><input type = "text" name = "fnm"><br>
Last name:<br><input type = "text" name = "lnm"><br>
Mobile:<br><input type = "text" name = "mob"><br>
Age:<br><input type = "number" name = "age"><br>
Source:<input type = "text" name = "src">
Destination:<input type = "text" name = "des"><br>
<font color="orange">Passenger Address:<br></font color>
Street:<br><input type = "text" name = "str"><br>
Area:<br><input type = "text" name = "area"><br>
City:<br><input type = "text" name = "cty"><br>

<input type = "submit">

</h3>
</center>
</form>

</body>
</html>

PHP代码:

    <?php
$con=mysqli_connect("localhost","root","","testdb");
if(mysqli_connect_error())
{
echo "FAILED" . mysqli_connect_error();
}
$sql="INSERT INTO exp VALUES('$_POST[fnm]', '$_POST[lnm]', $_POST[mob], $_POST[age], '$_POST[src]', '$_POST[des]', '$_POST[str]', '$_POST[area]', '$_POST[cty]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>

最佳答案

在这里,让我纠正一下语法:

$sql="INSERT INTO exp VALUES('".$_POST['fnm']."','".$_POST['lnm']."','".$_POST['mob']."', '".$_POST['age']."','".$_POST['src']."','".$_POST['des']."','".$_POST['str']."','".$_POST['area']."', '".$_POST['cty']."')";

关于php - 使用xampp的php mysql连接出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26189014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com