2015-11-04 68 views
-1

我試圖做一個註冊表單。在這一刻,我試圖將輸入數據插入到數據庫中。我得到語法錯誤,意外的'{'in ..我無法找到錯誤的地方..請幫助看看我的代碼。順便說一句,這是我編輯的問題,我之前發佈的關於空白頁錯誤的代碼..對不起,我英文破碎。 :d語法錯誤,意想不到的'{'

partner_registration.php:

<?PHP 
error_reporting(0); 
include ('connect.php'); 


if(isset($_POST['submit'])) 
{ 

// The form is submitted 

$c_name = ($_POST['txtName']); 
$c_type = ($_POST['selType']); 
$c_no = ($_POST['txtNo']); 
$c_address = ($_POST['txtAddress']); 
$c_city = ($_POST['txtCity']); 
$c_postcode = ($_POST['txtPostcode']); 
$c_state = ($_POST['selState']); 
$c_country = ($_POST['selCountry']); 
$c_email = ($_POST['txtEmail']); 
$c_phone = ($_POST['txtPhone']); 
$c_fax = ($_POST['txtFax']); 


$c_name = $mysqli->real_escape_string($c_name); 
$c_type = $mysqli->real_escape_string($c_type); 
$c_no = $mysqli->real_escape_string($c_no); 
$c_address = $mysqli->real_escape_string($c_address); 
$c_city = $mysqli->real_escape_string($c_city); 
$c_postcode = $mysqli->real_escape_string($c_postcode); 
$c_state = $mysqli->real_escape_string($c_state); 
$c_country = $mysqli->real_escape_string($c_country); 
$c_email = $mysqli->real_escape_string($c_email); 
$c_phone = $mysqli->real_escape_string($c_phone); 
$c_fax = $mysqli->real_escape_string($c_fax); 



// attempt insert query execution 
if ($insert = $mysqli->query ("INSERT INTO tblpartner (companyName, companyRegistration, companyNo, companyAddress, companyCity, companyPostCode, companyState, companyCountry, companyEmail, companyPhone, companyFax) VALUES ('$c_name', '$c_type', '$c_no', '$c_address', '$c_city','$c_postcode', '$c_state', '$c_country', '$c_email', '$c_phone', '$c_fax')") 
{ 
echo("Success", $mysqli->affected_rows); 
} 

} 

?> 

connect.php:

<?php 
$hostname="localhost"; //local server name default localhost 
$username="root"; //mysql username default is root. 
$password="1234";  //blank if no password is set for mysql. 
$database="intrasystem"; //database name which you created 

//Open a new connection to the MySQL server 
$mysqli = new mysqli('localhost','root','1234','intrasystem'); 

//Output any connection error 
if($mysqli->connect_errno) 
{ 
    die('Cannot connect to database'); 
} 

?> 
+0

你能看到錯誤日誌嗎? – raygo

+0

'$ con'是一個對象。在所有情況下使用OOP。這個'$ c_name = mysqli_real_escape_string($ con,$ _POST ['txtName']);'是程序性的。 – chris85

+1

閱讀'bind_param'手冊並檢查它的第一個參數。這是一個像'sssi''或類似的字符串。 –

回答

2

在這一行:

if ($insert = $mysqli->query ("... your sql query ...") 

你有兩個開放括號,但只有一個閉合。就在結尾處添加另一結束括號:

if ($insert = $mysqli->query ("... your sql query ...")) 
+0

它看起來像這樣(.......'$ c_email','$ c_phone','$ c_fax')「))因爲我得到了新的systax意外',' –

+0

我沒有看到任何錯位' ,'在你發佈的代碼。也許這有助於:http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them –

+0

意外的','是在線回聲(「成功」,$ mysqli-> affected_rows);寫這個的正確方法是什麼?我只回聲(「成功」),但我有空白頁後提交 –

0
if ($insert = $mysqli->query("INSERT INTO tblpartner (companyName, companyRegistration, companyNo, companyAddress, companyCity, companyPostCode, companyState, companyCountry, companyEmail, companyPhone, companyFax) VALUES ('".$c_name."', '".$c_type."', '".$c_no."', '".$c_address."', '".$c_city."','".$c_postcode."', '".$c_state."', '".$c_country."', '".$c_email."', '".$c_phone."', '".$c_fax."')")) 
{ 
    echo("Success", $mysqli->affected_rows); 
} 

使用PDO下一次。

相關問題