2014-10-04 90 views
0

我试图使用PHP的形式MySQL数据库使用XAMPP连接一个HTML页面的PHP MySQL连接。在HTML页面工作正常,但只要我按下提交按钮的网页具有鲜明的人物出现时,任何人可以用问题帮助[PHP页面] [1]错误使用XAMPP

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); 
    ?> 
+0

哪里是你的PHP代码? – iatboy 2014-10-04 02:26:27

+0

什么是“具有鲜明的字符的页面”? – 2014-10-04 02:28:13

+0

@iatboy我已将php代码 – 2014-10-04 02:32:21

回答

0

我知道这是太晚的家伙,但我解决了这个问题:要在其中插入值如下在语法上是正确的,你会想明确说明。这并不意味着花了我3年的时间来解决它,我只是忘记发布答案。这是因为我正在编写Wordpad中的php代码。我在记事本中复制并保存了代码,问题解决了。

谢谢您的宝贵意见家伙。

0

这个代码是错误的:$sql="INSERT INTO exp VALUES('$_POST[fnm]', '$_POST[lnm]', $_POST[mob], $_POST[age], '$_POST[src]', '$_POST[des]', '$_POST[str]', '$_POST[area]', '$_POST[cty]')";

,你是不是指$_POST variables using their name失踪周边日报价e变量名称。更正该行并且您的数据应该成功插入。

+0

不,它显示同样的错误页面,你可以更具体的修正吗? – 2014-10-04 02:43:27

3

在这里,请允许我纠正语法:

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

..加一个,很好的答案..:P – 2015-01-26 09:12:56

+0

哈哈。好的答案只是通过更正语法?:D – 2015-01-26 09:14:04

+0

但你解决了它:P – 2015-01-26 09:14:41

0

尝试使用下面的PHP,让我们知道会发生什么:

$sql="INSERT INTO `exp` VALUES('{$_POST['fnm']}', '{$_POST['lnm']}', 
    '{$_POST['mob']}', '{$_POST['age']}', '{$_POST['src']}', '{$_POST['des']}', 
    '{$_POST['str']}', '{$_POST['area']}', '{$_POST['cty']')" 
    or die('Error: ' . mysqli_error($con)); 
$output = $con->$sql 
echo "1 record added"; 
mysqli_close($con); 

是什么不同的这种方式?

注:

$sql="INSERT INTO `table_name` (`first_value`, `second_value`, `third_value`) 
    VALUES ('{value1}', '{value2}', '{value3}');";