错误:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在'@ ami.com','50cb0778758634b4a6f959ed4bf2debd')'附近的第144行
HTML CODE
<form action="" method="post">
<table>
<tbody>
<tr>
<td>
<div>
<input type="text" name="name" placeholder="Name">
</div>
<div>
<input type="text" name="city" placeholder="City">
</div>
<div>
<input type="text" name="zip" placeholder="Zip-Code">
</div>
<div>
<input style="padding:7px 10px; margin-top:5px;width:336px;" type="email" name="email" placeholder="Email" >
</div>
</td>
<td>
<div>
<input type="text" name="address" placeholder="Address">
</div>
<div>
<input type="text" name="country" placeholder="Country">
</div>
<div>
<input type="text" name="phone" placeholder="Phone">
</div>
<div>
<input style="padding:7px 10px; margin-top:5px;width:336px;" type="password" name="pass" placeholder="Password">
</div>
</td>
</tr>
</tbody>
</table>
<div class="search"><div><button class="grey" name="register">Create Account</button></div></div>
<p class="terms">By clicking 'Create Account' you agree to the <a href="#">Terms & Conditions</a>.</p>
<div class="clear"></div>
</form>
PHP代码
public function customerRegistration($data)
{
$name = mysqli_real_escape_string($this->db->link, $data['name']);
$address = mysqli_real_escape_string($this->db->link, $data['address']);
$city = mysqli_real_escape_string($this->db->link, $data['city']);
$country = mysqli_real_escape_string($this->db->link, $data['country']);
$zip = mysqli_real_escape_string($this->db->link, $data['zip']);
$phone = mysqli_real_escape_string($this->db->link, $data['phone']);
$email = mysqli_real_escape_string($this->db->link, $data['email']);
$pass = mysqli_real_escape_string($this->db->link, md5($data['pass']));
if ($name == "" || $address == "" || $city == "" || $country == "" || $zip == "" || $phone == "" || $email == ""|| $pass == "") {
$msg = "fileds must not be empty";
return $msg;
}
// email query
$mailquery = "SELECT * FROM tbl_customer WHERE email='$email' LIMIT 1";
$checkmail = $this->db->select($mailquery);
// password query
$passquery = "SELECT * FROM tbl_customer WHERE pass='$pass' LIMIT 1";
$checkpass = $this->db->select($passquery);
// return $checkmail;
if ($checkmail != false) {
$msg = "Email already exit";
return($msg);
} elseif( $checkpass != false) {
$msg = "Password already exit";
return($msg);
} else {
$query = "INSERT INTO tbl_customer(name, address, city, country, zip, phone, email, pass) VALUES('$name', '$address', '$city', '$country', '$zip', '$phone', $email, '$pass')";
$inserted_row = $this->db->insert($query);
if ($inserted_row) {
$msg = "Customer data inserted successfully";
return $msg;
} else {
$msg = "Customer data not inserted";
return $msg;
}
}
}
答案 0 :(得分:0)
'
已错过$email
;)
尝试更改
$query = "INSERT INTO tbl_customer(name, address, city, country, zip, phone, email, pass) VALUES('$name', '$address', '$city', '$country', '$zip', '$phone', $email, '$pass')";
到
$query = "INSERT INTO tbl_customer(name, address, city, country, zip, phone, email, pass) VALUES('$name', '$address', '$city', '$country', '$zip', '$phone', '$email', '$pass')";
答案 1 :(得分:0)
你的问题在这里:
$query = "INSERT INTO tbl_customer(name, address, city, country, zip, phone, email, pass) VALUES('$name', '$address', '$city', '$country', '$zip', '$phone', $email, '$pass')";
您错过了$ email中的单引号。就像这样(&#39; $ email&#39;)。
所以你的SQL命令将是:
$query = "INSERT INTO tbl_customer(name, address, city, country, zip, phone, email, pass) VALUES('$name', '$address', '$city', '$country', '$zip', '$phone', '$email', '$pass')";