0

My update of the database has no problems whatsoever. And down in my local development environment a new record insert also has no problems. I have tried changing my MySQL user many times because I thought it might be about permissions (maybe that is still the problem, I don't know). I have even made the user root and supplied my correct root password: again, I can perform updates, but no new record inserts. Here is my code which I have shortened (i.e taken out the large number of fields. It works locally, but not on the server).

I am on Ubuntu Linux, 16.04, PHP 7

$message = '';

$db = new mysqli('localhost', 'root', 'notrealpword', 'mydatabase');


if ($db->connect_error){

  $message = $db->connect_error;

}else{

//    echo $message ;

}

$prep = $db->prepare("INSERT INTO users (userid, username) VALUES 
('0',?)");
//Now, you can bind some parameters.
$prep->bind_param('s',$username);

$username = "atservertest";


$prep->execute();

$numaffected = $prep->affected_rows ;

echo $numaffected;

//        echo $numaffected . " row(s) affected." ;

$prep->close();
1

3 Answers 3

2

FIXED MY OWN PROBLEM:

This is caused by the STRICT_TRANS_TABLES SQL mode.

Open phpmyadmin and goto More Tab and select Variables submenu. Scroll down to find sql mode. Edit sql mode and remove STRICT_TRANS_TABLES Save it.

My local phpmyadmin settings were different than the settings for phpmyadmin up at my new server. ... Note that to made the configuration changes above I needed to login as root at phpmyadmin ...

Sign up to request clarification or add additional context in comments.

1 Comment

You saved my life. I’ve been working hours and couldn’t find a solution. This one works.
1

$username must initialize first.

//Call this first
$username = "atservertest";
//Then use bind_param
$prep->bind_param('s',$username);

1 Comment

Thanks. But I just tried that, but I still get -1 for the number of rows effected. Also, I was using it on my local development environment initializing the $username AFTER and it was working fine.
0

It works, my environment is MacOS and PHP 7.1.12, MySQL 5.6.21

Add code:

$prep->execute();
// see if any error happend
var_dump($db->error_list, $db->error);

to see if any error happend. If no error, then the result should be

array(0) {
}
string(0) ""

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.