magcr23 Posted June 16, 2015 Share Posted June 16, 2015 Hi guys, i have this code: $sql="SELECT * FROM admin"; $resultado = mysqli_query($con, $sql); $row=mysqli_fetch_array($resultado,MYSQLI_NUM); <?php echo $row[0] ?> It returns the first user of the table, but i want the user who's loged, someone can help me with that? Link to comment https://forums.phpfreaks.com/topic/296843-php-and-mysqli/ Share on other sites More sharing options...
Ch0cu3r Posted June 16, 2015 Share Posted June 16, 2015 Apply a WHERE clause to your select query (I am guessing the username/userid field name and variable) $sql="SELECT * FROM admin WHERE user = '$user'"; Link to comment https://forums.phpfreaks.com/topic/296843-php-and-mysqli/#findComment-1514037 Share on other sites More sharing options...
magcr23 Posted June 16, 2015 Author Share Posted June 16, 2015 I tried to do something like that: $row=mysqli_fetch_array($resultado,MYSQLI_ASSOC); $user = $row['user']; echo $user; But the result is the same. Can you tell me what am i doing wrong? Or modify my code to do what i need? I need this problem solved to continue with my project, or i'll fail in my class xD Link to comment https://forums.phpfreaks.com/topic/296843-php-and-mysqli/#findComment-1514039 Share on other sites More sharing options...
magcr23 Posted June 16, 2015 Author Share Posted June 16, 2015 I think that half of the problem is solved, with that i can see the right user who's logged. $row=mysqli_fetch_array($resultado,MYSQLI_ASSOC); $user2 = $_SESSION["user"]; echo $user2; But how can i update an password? I tryed with that: $updatePW= "UPDATE admin SET password = sha1('$new') WHERE user = password = sha1('$old') "; But it update all the equal passwords. So i tryed with that: $updatePW= "UPDATE admin SET password = sha1('$new') WHERE user = $user2 && password = sha1('$old') "; But it don't work... What can i do? Link to comment https://forums.phpfreaks.com/topic/296843-php-and-mysqli/#findComment-1514049 Share on other sites More sharing options...
Ch0cu3r Posted June 16, 2015 Share Posted June 16, 2015 $user2 needs to be wrapped in quotes in the query $updatePW= "UPDATE admin SET password = sha1('$new') WHERE user = '$user2' AND password = sha1('$old') "; Link to comment https://forums.phpfreaks.com/topic/296843-php-and-mysqli/#findComment-1514050 Share on other sites More sharing options...
magcr23 Posted June 16, 2015 Author Share Posted June 16, 2015 $user2 needs to be wrapped in quotes in the query $updatePW= "UPDATE admin SET password = sha1('$new') WHERE user = '$user2' AND password = sha1('$old') "; I miss that, thx xD Link to comment https://forums.phpfreaks.com/topic/296843-php-and-mysqli/#findComment-1514055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.