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

标签 php mysql database-connection

我正在尝试使用 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/

相关文章:

php - 拉维尔 5 + PostgreSQL : "Database [postgres] not configured." Error

php - 属性路径 "App\Entity\PageParagraph"处给出的预期参数类型为 "array"、 "paragraphs"

php sql插入表

mysql - 如何将日期字符串转换为 mysql 日期格式以使用 mysql 查询计算日期差异

hibernate - 如何正确关闭和打开 Hibernate session ?

php - 用于验证 linux 文件名的正则表达式(多编码)

php - 无法连接到本地主机中的 wordpress (GET http://localhost/net::ERR_CONNECTION_REFUSED)

mysql - SQL识别k天内下单次数超过m次的客户

java - JTable 未填充从数据库中提取的数据

azure - 从 Azure 服务连接到本地 SQL 数据库时出现间歇性错误