2016-07-28 42 views
-1

Fatal error: Uncaught Error: Call to a member function query() on string in C:\xampp\htdocs\boobae\index.php:58 Stack trace: #0 {main} thrown in雖然製作一個簡單的形式,我得到一個「致命錯誤:未捕獲的錯誤:調用一個成員函數查詢()」

C:\xampp\htdocs\boobae\index.php on line 58

這裏是我的代碼:

<?php include './include/header.include.php'; ?> 
<?php include './include/connect.include.php';?> 
<?php $reg = @$_POST['reg']; 

//declaring the variables to prevent errors 
$fn = ""; 
$ln = ""; 
$un = ""; 
$em = ""; 
$em2 = ""; 
$pswd = ""; 
$pswd2 = ""; 
$d_birth = ""; 
$d = ""; 
$u_check = ""; 
$phone_number = ""; 
$conn=""; 

//registration form 
$fn = strip_tags(@_POST['fname']); 
$ln = strip_tags(@_POST['lname']); 
$un = strip_tags(@_POST['uname']); 
$em = strip_tags(@_POST['email1']); 
$em2 = strip_tags(@_POST['email2']); 
$pswd = strip_tags(@_POST['passwprd1']); 
$pswd2 = strip_tags(@_POST['password2']); 
$d_birth = strip_tags(@_POST['dbirth']); 
$d = ('Y-M-D'); 
$phone_number = strip_tags(@_POST['phone_number']); 

if (isset($_POST['reg'])) { 
if ($em==$em2) { 
} 
else { 
echo "Your emails do not match!"; 
} 
if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) { 
echo "The maximum limit for username/first name/last name is 25 characters"; 
} 
if (strlen($pswd)>30||strlen($pswd)<5) { 
echo "Your password must be 5 to 30 characters long"; 
} 
if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2) { 
} 
else{ 
    echo "Please fill in all the fields!";} 
    if ($pswd==$pswd2) { 
} 
else { 
echo "Your pasword do not match!"; 
} 

$sql="INSERT INTO userss (username,first_name,last_name, email, password, 
d_birth, sign_up_date, $phone_number,activated) 
VALUES ('$un', '$fn', '$ln', '$em', '$pawd', '$d_birth', '$d', 
'$phone_number')"; 
//$insert=$con->query($sql); 
} 

if ($conn->query($sql) === TRUE) { 
    echo "New record created successfully"; 
} 
else { 
    echo "Error: " . $sql . "<br>" . $conn->error; 
} 

$conn->close(); 
+0

顯示您的$ conn變量(沒有密碼等課程)。看來$ conn是一個連接字符串,而不是一個SQL連接。 – Janno

+0

'$ conn =「」;'很明顯,這是行不通的,也許你會覆蓋已經在'connect.include.php'中指定的變量? – Bert

回答

1

您設定$conn="";權下$phone_number = "";$conn需要是數據庫連接,而不是一個字符串

0

在你當前的代碼$conn="";裏面顯然是一個字符串。首先使它成爲db連接變量。希望這可以幫助。

相關問題