MD Habib Ullah MD Habib Ullah - 5 months ago 7
MySQL Question

How can i solve this type of mysql error

ERROR:


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 '@ami.com, '50cb0778758634b4a6f959ed4bf2debd')' at line 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 &amp; Conditions</a>.</p>
<div class="clear"></div>
</form>


PHP CODE

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;
}
}
}

Answer

Your Problem is Here:

$query = "INSERT INTO tbl_customer(name, address, city, country, zip, phone, email, pass) VALUES('$name', '$address', '$city', '$country', '$zip', '$phone', $email, '$pass')";

You have missed single quote mark in $email. It will be like this ('$email').

So Your SQL Command would be:

$query = "INSERT INTO tbl_customer(name, address, city, country, zip, phone, email, pass) VALUES('$name', '$address', '$city', '$country', '$zip', '$phone', '$email', '$pass')";