NaderH Posted May 6, 2023 Author Share Posted May 6, 2023 19 hours ago, ginerjm said: All you had to do was add an echo and then cut and paste it to here. Ok - had enough. That's the echo code I used for all queries <p>Role changing query</p> <?php $update = "UPDATE blog.roles SET role_status = '0' WHERE id ='2'"; $uresult = $db->query($update) or die ($update."<br/><br/>".mysql_error()); if($uresult && $db->affected_rows() === 1) { echo ('Role status changed successfuly'); } else { echo ('Role status changing failed'); } ?> <br> <p>Users with role blocked selecting query</p> <?php $selectb = "SELECT users.username FROM blog.users JOIN blog.roles ON roles.id = users.user_level WHERE roles.role_status = '0'"; $sbresult = mysql_query($selectb) or die ($selectb."<br/><br/>".mysql_error()); while($sbrow = mysql_fetch_assoc($sbresult)) { echo $sbrow['username']; // Print a single column data echo print_r($sbrow); } // Print the entire row data ?> <br> <p>Users with role allowed selecting query</p> <?php $selecta = "SELECT users.username FROM blog.users JOIN blog.roles ON roles.id = users.user_level WHERE roles.role_status = '1'"; $saresult = mysql_query($selecta) or die ($selecta."<br/><br/>".mysql_error()); while($sarow = mysql_fetch_assoc($saresult)) { echo $sarow['username']; // Print a single column data echo print_r($sarow); } // Print the entire row data and that's the output Role changing query Role status changed successfuly Users with role blocked selecting query Editor@userArray ( [username] => Editor@user ) 1 Users with role allowed selecting query Admin@userArray ( [username] => Admin@user ) 1User@userArray ( [username] => User@user ) 1 Actually, I don't know.. aren't you believe that the queries are working or what!! Quote Link to comment https://forums.phpfreaks.com/topic/316257-php-function-error-notice-undefined-index/page/2/#findComment-1608121 Share on other sites More sharing options...
NaderH Posted May 6, 2023 Author Share Posted May 6, 2023 19 hours ago, Barand said: Did you check what the find_by_id() function wasputting in the array? yes the id of the user from the users table ( if you used it with the users ) function find_by_id($table,$id) { global $db; $id = (int)$id; if(tableExists($table)){ $sql = $db->query("SELECT * FROM {$db->escape($table)} WHERE id='{$db->escape($id)}' LIMIT 1"); if($result = $db->fetch_assoc($sql)) return $result; else return null; } } Quote Link to comment https://forums.phpfreaks.com/topic/316257-php-function-error-notice-undefined-index/page/2/#findComment-1608122 Share on other sites More sharing options...
Barand Posted May 6, 2023 Share Posted May 6, 2023 Because it uses "SELECT * ... " it tells us nothing about what the keys are in the returned array. They will be the same as the column names, but we don't know the user table structure. Quote Link to comment https://forums.phpfreaks.com/topic/316257-php-function-error-notice-undefined-index/page/2/#findComment-1608124 Share on other sites More sharing options...
NaderH Posted May 6, 2023 Author Share Posted May 6, 2023 4 minutes ago, Barand said: Because it uses "SELECT * ... " it tells us nothing about what the keys are in the returned array. They will be the same as the column names, but we don't know the user table structure. That's the users table structure id user_name user_level --------------------------------------- 1 Admin 1 2 Editor1 2 3 User1 3 4 Editor2 2 5 User2 3 6 User3 3 Quote Link to comment https://forums.phpfreaks.com/topic/316257-php-function-error-notice-undefined-index/page/2/#findComment-1608128 Share on other sites More sharing options...
Barand Posted May 6, 2023 Share Posted May 6, 2023 On 5/5/2023 at 3:13 PM, NaderH said: It printed all user data Array ( [id] => [name] => [username] => [password] => [user_level] => [image] => [status] => [last_login] => ) Where does the above data come from then? Quote Link to comment https://forums.phpfreaks.com/topic/316257-php-function-error-notice-undefined-index/page/2/#findComment-1608130 Share on other sites More sharing options...
NaderH Posted May 6, 2023 Author Share Posted May 6, 2023 13 minutes ago, Barand said: Because it uses "SELECT * ... " it tells us nothing about what the keys are in the returned array. They will be the same as the column names, but we don't know the user table structure. That's the main structure Array ( [id] => [name] => [username] => [password] => [user_level] => [image] => [status] => [last_login] => ) But this this the one I am working on ( for testing) Array ( [id] => [username] => [user_level] => ) Quote Link to comment https://forums.phpfreaks.com/topic/316257-php-function-error-notice-undefined-index/page/2/#findComment-1608131 Share on other sites More sharing options...
NaderH Posted May 6, 2023 Author Share Posted May 6, 2023 (edited) 2 minutes ago, Barand said: Where does the above data come from then? I am afraid of corrupting my main project so I am working on another one for testing, Sorry I am still beginner. Edited May 6, 2023 by NaderH Quote Link to comment https://forums.phpfreaks.com/topic/316257-php-function-error-notice-undefined-index/page/2/#findComment-1608133 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.