user2074648 user2074648 - 1 year ago 78
PHP Question

PHP 7.0 strange issue with inserting record

Before you ask, I did search the site and did not find that anyone had a similar issue yet.

I'm just upgrading some code to PHP 7.0 with mysqli functions so it's all new to me. I have a function that will add a record if no id is passed in or update it if an id is passed in. The update part of it works but the insert doesn't. I've tried to echo the query and nothing shows to the screen. It used to work with mysql functions. I have also echoed the role id and it is definitely 0.

It might be something a PHP expert will spot rather quickly, so forgive a newbie like me.

Code below.

function saveRole($role_id=0,$role) {

global $database,$form; // the database and form objects, nothing wrong with the connection

if($form->value('role') == "")
$form->setError("role",$role); // this is handled by the form object

if($form->num_errors == 0)

if($role_id == 0){
$q="INSERT INTO ".TBL_USER_ROLES." (role) VALUES ('".$role."')";
echo $q; // nothing shows?

else {
" SET role='".$role."'".
" WHERE role_id=". $role_id;


Answer Source

rewrite if condition seems $role_id undefined

if($role == 0){