2013-07-28 37 views
2

這是包含窗體本身我的index.php頁面:我在註冊表單操作頁面上收到錯誤信息?

<html> 
<body> 

<form action="registeraction.php" method="post"> 
First Name: <input type="text" name="fname"><br> 
Last Name: <input type="text" name="lname"><br> 
Email Address: <input type="text" name="emaddress"><br> 
Confirm Email Address: <input type="text" name="confirmemaddress"><br> 
Password: <input type="password" name="pword"><br> 
Confirm Password: <input type="password" name="confirmpword"><br> 
<input type="submit"> 
</form> 

</body> 
</html> 

這是我registeraction.php頁面處理表單:

<?php 
$con=mysqli_connect("localhost", "root", "", "registration_info"); 
//Check Connection 
if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

mysqli_query($con,"INSERT INTO Registration_Basics (fname, lname, emaddress,   
confirmemaddress, pword, confirmpword) 
VALUES 
('$_POST[fname]','$_POST[lname]','$_POST[emaddress]','$_POST[confirmemaddress]',   
'$_POST[pword]', '$_POST[confirmpword]')"; 

if (!mysqli_query($con,$sql)) 
{ 
die('Error: ' . mysqli_error($con)); 
} 
echo "1 Record Added"; 

mysqli_close($con); 
?> 

這是我得到我時錯誤用表單中的所有信息運行registeraction.php文件:解析錯誤:語法錯誤,意外的';'在C:\ XAMPP \ htdocs中\ TutorialBoy \ registeraction.php上線11

+1

[點擊這裏瞭解如何使用的MySQLi看到一個很好的例子,它也將幫助你找出爲什麼你不工作。(http://stackoverflow.com/questions/17123481/insert-data-into-table-using-php/17123740#17123740)請記住,您正在使用MySQLi,但您直接在查詢中注入數據,這使您很容易受到SQL注入的影響,我剛纔提到的例子也會告訴你如何使用預處理語句。 – Prix

+0

當然,你正在發佈一個接一個的錯誤。建議@Prix,評論。 – vee

回答

0

你缺少一個右括號這裏:

mysqli_query($con,"INSERT INTO Registration_Basics (fname, lname, emaddress,   
confirmemaddress, pword, confirmpword) 
VALUES 
('$_POST[fname]','$_POST[lname]','$_POST[emaddress]','$_POST[confirmemaddress]',   
'$_POST[pword]', '$_POST[confirmpword]')"); <---- here 

更新:

新的錯誤意見後,請有看看http://php.net/manual/en/mysqli.query.php

你的is(mysqli_query($con, $sql)呼叫是不正確的。如果你看一下文檔,你應該能夠把它弄出來。

猜你想做到這一點:

$sql = "INSERT INTO Registration_Basics (fname, lname, emaddress,   
confirmemaddress, pword, confirmpword) 
VALUES 
('$_POST[fname]','$_POST[lname]','$_POST[emaddress]','$_POST[confirmemaddress]',   
'$_POST[pword]', '$_POST[confirmpword]')"; 

if (!mysqli_query($con, $sql)) 
{ 
    die('Error: ' . mysqli_error($con)); 
} 
+0

謝謝,但現在我得到了這些新的錯誤:注意:未定義的變量:sql中的C:\ xampp \ htdocs \ TutorialBoy \ registeraction.php on line 13 警告:mysqli_query():C:\ xampp \ htdocs \第13行的TutorialBoy \ registeraction.php –

+0

@DevinSmith,請張貼您的「新錯誤」。 – vee

+0

謝謝,但現在我得到了這些新的錯誤:注意:未定義的變量:第13行的C:\ xampp \ htdocs \ TutorialBoy \ registeraction.php中的sql警告:mysqli_query():C:\ xampp \ htdocs \ TutorialBoy中的空查詢\ registeraction.php在線13 –

0

此行應該是...

mysqli_query($con,"INSERT INTO Registration_Basics (fname, lname, emaddress,confirmmaddress, pword, confirmpword) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[emaddress]','$_POST[confirmemaddress]', $_POST[pword]', '$_POST[confirmpword]')"); 

你失蹤的支架

0

替換查詢
$sql = mysqli_query($con,"INSERT INTO Registration_Basics (fname, lname, emaddress,   
confirmemaddress, pword, confirmpword) 
    VALUES 
    ('".$_POST['fname']."','".$_POST['lname']."','".$_POST['emaddress']."','".$_POST['confirmemaddress']."',   
'".$_POST['pword']."', '".$_POST['confirmpword']."') "); 

在將它們插入查詢之前,您必須轉義所有變量。

+0

謝謝,但現在我得到這些新的錯誤:注意:未定義的變量:sql中的C:\ xampp \ htdocs \ TutorialBoy \ registeraction。php on line 13警告:mysqli_query():在第13行的C:\ xampp \ htdocs \ TutorialBoy \ registeraction.php中的空查詢 –

+0

ok編輯我的答案現在試試吧 –

1

使用的mysqli和參數化查詢:

$con=mysqli_connect("localhost", "root", "", "registration_info"); 
//Check Connection 
if (mysqli_connect_errno()) 
{ 
echo die("Failed to connect to MySQL: " . mysqli_connect_error()); 
} 
$query = " 
INSERT INTO Registration_Basics 
(fname, lname, emaddress, confirmemaddress, pword, confirmpword) 
VALUES 
(?,?,?,?,?,?) 
"; 
if ($stmt = mysqli_prepare($con, $query)) { 

    mysqli_stmt_bind_param($stmt, "ssssss", $_POST['fname'], $_POST['lname'],$_POST['emaddress'], 
    $_POST['confirmemaddress'],$_POST['pword'], $_POST['confirmpword']); 

    /* execute query */ 
    mysqli_stmt_execute($stmt); 

    if(mysqli_affected_rows($con) > 0){ 
    echo "Inserted"; 
    }else{ 
    echo "Error:".mysqli_error(). " Error No:". mysqli_errno(); 
    } 
    /* close statement */ 
    mysqli_stmt_close($stmt); 
} 
+0

@Prix:謝謝我明白了:)請編輯它不用謝 – 2013-07-28 23:28:40

相關問題