I am getting a very funny problem with my code. Basically the first time when I run the code I get the correct result from the mysqli_effected_rows()
function. But the second time I run the same script it keeps giving me "-100"
If I delete all the records in the table and run the code again I get the correct result from mysqli_effected_rows()
function.
is "-100" an error code ?
$count ="";
foreach($database as $key=>$value) {
foreach($value as $field => $cell){
if ($field =='itemid') {
echo "the item id is $cell <br />";
$col1 = $cell ;
}
elseif ($field =='title') {
echo "the title is $cell<br />";
$col2 = $cell;
}
elseif ($field =='starttime') {
echo "the start time is $cell<br />";
$col3 = $cell;
}
}
$dbquery = "INSERT INTO cordless_drill(itemid,title,starttime) VALUES ('$col1','$col2','$col3')";
mysqli_query($dbc,$dbquery);
$count += mysqli_affected_rows($dbc);
}
echo $count ;
Get the number of affected rows by the last INSERT
, UPDATE
, REPLACE
or DELETE
query associated with link_identifier
. The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect()
is assumed. If no such link is found, it will try to create one as if mysql_connect()
was called with no arguments. If no connection is found or established, an E_WARNING level
error is generated. Returns the number of affected rows on success, and -1 if the last query failed. Before attempting $count += mysqli_affected_rows($dbc);
just try to echo the values of mysqli_affected_rows($dbc)
... and check any warning occurs ....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.