0

I am using PHP to check the sql data, but if I am using variable to write in the sql code, it can't get the result in the page.

Below is my coding, if I put the variable is $user_id, it can't get the result to see:

<?php
    $sql_incharge = 'select * from user_permission where user_id='.$user_id' and menu_id=228';
    $arr_incharge = db_conn_select($sql_incharge);
    //print_r($arr_incharge);
    foreach ($arr_incharge as $rs_incharge) {
        $test88 = $rs_incharge['is_edit'];
        echo $test88;
        }
        ?>

What I have tried:

  1. If I hardcode the number replace $user_id, it can get the result.
  2. If without menu_id ,like this code 'select * from user_permission where user_id='.$user_id, it can get the result.

But I want two condition (user_id and menu_id) to check my record, hope anyone can guide me how to show the record when I am using variable.

  • what are the column type? – Gabriel May 11 '20 at 04:49
  • Please use error reporting. That would have told you your issue... you shouldnt write SQL like this though. It should be `select * from user_permission where user_id=? and menu_id=228` then bind `$user_id`. Look at parameterized queries and prepared statements. – user3783243 May 11 '20 at 04:52

0 Answers0