Baris Sarac
Baris Sarac

Reputation: 115

Cannot Check If MySQLi Recorded Values Successfully

I have the code below to submit values to the database using PHP. I am trying to check if the query has been successfully run to save the data to the database. If cycle ends up not being TRUE even tough it successfully saves the data. What is wrong with it?

$sql = "INSERT INTO  `stsadad_cWmFRJ`.`bin` (`id` ,`time` ,`subu` ,`saba` ,`url`)
                                      VALUES (NULL , CURRENT_TIMESTAMP ,  '".$subu."',  '".$saba."',  '".$url."')";
$mysqli->query($sql);

if($mysqli->query($sql) === TRUE) {
    echo "Recorded successfully";
} else {
    echo "There's problem";
}

Upvotes: 0

Views: 66

Answers (1)

Subin Thomas
Subin Thomas

Reputation: 1416

$mysqli->query($sql); //inserting data to table

this code already inserts the data.

if($mysqli->query($sql) === TRUE) //Inserting data and checking its true or false.

This is like you insert the data two times.

so this code will be false, if any of your column defined unique

One of this line is enough, So remove this line $mysqli->query($sql);

Upvotes: 1

Related Questions