'Incorrect integer value' for an SQL Query inside a PHP script
Get the solution ↓↓↓The following query works fine in SQL but not as an SQL Query in PHP for some reason. The error message is as follows:
Incorrect integer value: 'SELECT id FROM colours WHERE colour = ' for column
databasename
.numbers
.col_id
at row 1
$redID = "SELECT id FROM colours WHERE colour = $red";
$populate = "INSERT INTO numbers (col_id) VALUES ('$redID')";
$result=$conn->query($populate);
Answer
Solution:
Your populate query cannot accept an SQL String as a col_id.
$redIDSQL = "SELECT id FROM colours WHERE colour = '$red'";
$redIDQuery=$conn->query($redIDSQL);
$redIDArray=array();
while($redIDResult=mysqli_fetch_assoc($redIDQuery)){
$redIDArray[]=$redIDResult['id'];
}
if(count($redIDArray)>0){
$populateSQL = "INSERT INTO numbers (col_id) VALUES ('".implode("'),('",$redID)."')";
$populateQuery=$conn->query($populateSQL);
}else{
echo "redID could not be found with colour matching ".$red;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illuminate\http\exceptions\posttoolargeexception
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.