thunder708 Posted March 3, 2010 Share Posted March 3, 2010 hi all! right i have two files, login.php and users.php. users.php <? $user = array(); // Set Users $user[0]["name"]='liam'; $user[0]["pass"]='lol'; $user[1]["name"]='mike'; $user[1]["pass"]='rofl'; ?> and in the login.php i have a form that you type in a user and pass and it logs you in, i know how to do this if i set the values within the login file itself but i want to be able to use this array i have made. so my question is, how do i search the array for the required user and pass when it is submitted from the form? Link to comment https://forums.phpfreaks.com/topic/193950-getting-data-from-php-array/ Share on other sites More sharing options...
trq Posted March 3, 2010 Share Posted March 3, 2010 foreach ($user as $u) { if ($u['name'] == $_POST['name'] && $u['pass'] == $_POST['pass']) { // username password matches. } } Link to comment https://forums.phpfreaks.com/topic/193950-getting-data-from-php-array/#findComment-1020699 Share on other sites More sharing options...
thunder708 Posted March 3, 2010 Author Share Posted March 3, 2010 thanks, this works if i put the contents of users.php into the main file but doesnt work if i include the file... any ideas? Link to comment https://forums.phpfreaks.com/topic/193950-getting-data-from-php-array/#findComment-1020717 Share on other sites More sharing options...
trq Posted March 3, 2010 Share Posted March 3, 2010 Including the file should work fine. Post your code. Link to comment https://forums.phpfreaks.com/topic/193950-getting-data-from-php-array/#findComment-1020720 Share on other sites More sharing options...
thunder708 Posted March 3, 2010 Author Share Posted March 3, 2010 $user = $_REQUEST['user']; // requests user from form $pass = $_REQUEST['pass']; // requests pass from form include("users.php"); foreach ($users as $u) { if ($u['name'] == $user && $u['pass'] == $pass) { echo "well don eyou have logged in "; } } Link to comment https://forums.phpfreaks.com/topic/193950-getting-data-from-php-array/#findComment-1020756 Share on other sites More sharing options...
thunder708 Posted March 3, 2010 Author Share Posted March 3, 2010 i have figured out what i have done wrong, i had changed your code to say foreach ($users as $u) { and changed the users file to say $users[0]["name"]='liam'; $users[0]["pass"]='lol'; but forgot to change the declaration to $users = array(); it was still $user = array(); my bad thank you anyway Link to comment https://forums.phpfreaks.com/topic/193950-getting-data-from-php-array/#findComment-1020803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.