2014-10-04 46 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}');";