I keep getting this same error when i try to submit an appointment request to sql

I’m pretty new to sql and php.

I’m trying to submit this form into mysql server but I keep getting this error…i’m not sure where the mistake is…

Error: INSERT INTO grooming (Address, Breed, City, Email, Firstname, Lastname, NeuteredOrSpayed, PetName, PetType, PhoneNumber, State, Zip) VALUES (‘123 Main St’,’Chihuahua’,’Los Angeles’,’[email protected]’,’John’,’Doe’,’Yes’,’Iris’,’Dog’,'(555)123-4568′,’CA’,’90001′) Incorrect integer value: ‘Yes’ for column ‘NeuteredOrSpayed’ at row 1

This is the code:

<?php  $servername = "localhost"; $username = "root"; $password = "pwdpwd"; $dbname = "pet_shop";   $db = new mysqli($servername, $username, $password, $dbname);  if (mysqli_connect_errno()) { echo 'Could not connect: ' . mysql_error(); } else {  function clean_data($data) {     $data = trim($data);     $data = stripslashes($data);     $data = htmlspecialchars($data);     return $data; }   $firstname = clean_data($_POST['aptfirstname']); $lastname = clean_data($_POST['aptlastname']); $address = clean_data($_POST['aptaddress']); $city = clean_data($_POST['aptcity']); $state = clean_data($_POST['aptstate']); $zip = clean_data($_POST['aptzip']); $phonenumber = clean_data($_POST['aptphonenumber']); $email = clean_data($_POST['aptemail']); $petname = clean_data($_POST['aptpetname']); $neutered = clean_data($_POST['aptneutered']); $pettype = clean_data($_POST['aptpettype']); $breed = clean_data($_POST['aptbreed']);    if ($neutered == "true") {     $neutered = "Yes"; } else {     $neutered = "No"; }  if ($pettype == "Cat") {     $breed = "";  }   $sql = "INSERT INTO grooming (Address, Breed, City, Email, FirstName, LastName, NeuteredOrSpayed, PetName, PetType, PhoneNumber, State, Zip) VALUES ('$address', '$breed', '$city', '$email', '$firstname', '$lastname', '$neutered', '$petname', '$pettype', '$phonenumber', '$state', '$zip')";  if ($db->query($sql) === TRUE) {     echo "success";  } else {     echo "Error: " . $sql . "<br>" . $db->error; }  $db->close(); }   ?> 

If you need more context to the form code I can post that as well, it was just a lot to post up on here

Asked on July 16, 2020 in Mysql.
Add Comment
2 Answer(s)

Its a simple datatype error the column you have in database called neutered has a datatype of Integer and the value you trying to insert is ‘Yes’ which is absolutely not an integer.

Try putting integer 1 and 0 for yes and no respectively.

Answered on July 16, 2020.
Add Comment

it’s very clear.. as @Berto99 and @Pete and others mentioned..

column ‘NeuturedOrSpayed’ datatype is INT, so in your code it should be like this

if ($neutered == "true") {     $neutered = 1; # it was 'Yes' --> string, need to be int, so 1 } else {     $neutered = 0; # it was 'No' --> string, need to be int, so 0 } 
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.