嘿傢伙我有pp.php文件插入不工作,沒準備,綁定和執行,但不工作
<?php
class system{
public function register() {
if ($_POST) {
if ($_POST['password'] == $_POST['reppassword']) {
if ($_POST['email'] == $_POST['repemail']) {
$logdb = new PDO('mysql:host=localhost;dbname=kikojust', 'kikojust', '123456');
$logdb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $logdb->prepare('INSERT INTO usreg
(email, password, firstname, lastname, phone, mobile, adress, city, postalcode, country)
VALUES
(:email, :pass, :fname, :lname, :phone, :mobile, :adress, :city, :code, :country');
$stmt->bindParam(":email", $_POST['email'],PDO::PARAM_STR, 20);
$stmt->bindParam(":pass", $_POST['password'],PDO::PARAM_STR, 20);
$stmt->bindParam(":fname", $_POST['firstname'],PDO::PARAM_STR, 20);
$stmt->bindParam(":lname", $_POST['lastname'],PDO::PARAM_STR, 20);
$stmt->bindParam(":phone", $_POST['phone'],PDO::PARAM_STR, 16);
$stmt->bindParam(":mobile", $_POST['mobile'],PDO::PARAM_STR, 16);
$stmt->bindParam(":adress", $_POST['adress'],PDO::PARAM_STR, 50);
$stmt->bindParam(":city", $_POST['city'],PDO::PARAM_STR, 10);
$stmt->bindParam(":code", $_POST['postalcode'],PDO::PARAM_STR, 10);
$stmt->bindParam(":country", $_POST['country'],PDO::PARAM_STR, 14);
$stmt->execute();
echo 'You have being well donne registered, go to <a href="index.php">Login</a> to enter in our site';
} else {
echo 'Go back to <a href="register.php">Register</a> and check your Email';
}
} else {
echo 'Go back to <a href="register.php">Register</a> and check your password.';
}
} else {
echo '
<html>
<head>
<title>
Register!
</title>
</head>
<body>
<form name="login" action="" method="POST">
First Name:
<input type="text" name="firstname"/>
Last Name:
<input type="text" name="lastname"/>
<br />
Password:
<input type="password" name="password"/>
Repeat Password:
<input type="password" name="reppassword"/><br />
<br />
Email:
<input type="text" name="email"/>
Repeat Email:
<input type="text" name="repemail"/><br />
<br />
Phone:
<input type="tel" name="phone"/>
Mobile:
<input type="tel" name="mobile"/><br />
<br />
Adress: <br />
<input type="text" name="adress"/><br />
City: <br />
<input type="text" name="city"/><br />
Postal Code: <br />
<input type="text" name="postalcode"/><br />
Country: <br />
<input type="text" name="country"/><br />
<button type="submit">Register</button>
</form>
</body>
</html>';
}
}
}
此代碼,我有這個在register2.php
<?php
require_once 'Inc/pp.php';
$login = new system;
$login->register();
和通檢查,郵件檢查工作正常,一切看起來都很正常,直到它去插入部分,它給我的錯誤
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4' in
/home/kikojust/public_html/Inc/pp.php:26 Stack trace: #0
/home/kikojust/public_html/Inc/pp.php(26): PDOStatement->execute() #1
/home/kikojust/public_html/register2.php(4): system->register() #2 {main} thrown in
/home/kikojust/public_html/Inc/pp.php on line 26
,但我沒有得到什麼問題,導致stmt語句準備和綁定,但沒有運行,所有的entrys如表中所示,如果我在sql控制檯中運行相同的sql它很好,什麼是失敗在我的代碼中,你們可以告訴我嗎? thk
爲什麼不SQL語句與結束');「' – Max
爲max是說,你缺少右括號這是你查詢的'VALUES'部分的一部分 –
omg 1個簡單的圓括號將我的頭轉了幾個小時,thks傢伙,真的是那個;)非常感謝你 – kjonh2