benjihana Posted October 5, 2007 Share Posted October 5, 2007 Hello! This script is parsing username, fname, and lname correctly, but it is only sending the first letter of the password! Help! $sql = 'SELECT username, password, fname, lname FROM authentication WHERE 1'; $sql_result = mysql_query($sql,$dbh) or die ("Couldn't execute username query."); $totalusers = 0; while ($row = mysql_fetch_array($sql_result)) { $user [$totalusers] = $row["username"]; $pass [$totalusers] = $row["password"]; $fname [$totalusers] = $row["fname"]; $lname [$totalusers] = $row["lname"]; $totalusers = $totalusers + 1;} ... ... $checkusers = 0; while($checkusers < $totalusers) { if($_POST['username'] == $user [$checkusers] && $_POST['password'] == $pass [$checkusers]){ $_SESSION['name'] = $user [$checkusers]; $_SESSION['realname'] = $fname [$checkusers]." ".$lname [$checkusers]; //adds the users data to the php session $_SESSION['pass'] = $pass [$checkusers]; $logink = true; } $checkusers = $checkusers + 1; } //insert html for sucessfull log on here //you can use . $_SESSION['name'] . for username // replace name with realname, url, email to display different name if ($logink == true){ ?> You are logged in.<br> You may logout <a href="logout.php">here</a>. </body> </html> <?php } if($logink !== true) { // Some TESTING echo $user [$checkusers]; echo $checkusers; echo $totalusers; $run = 3; echo $run; echo $user [0]; echo $user [1]; echo $user [2]; $pass [0] = "test"; echo $pass [0]; echo $pass [1]; echo $_POST['username']; echo $_POST['password']; $test [0] = "monkey"; $test [1] = "bananas"; echo $test [0]; echo $test [1]; echo $fname [1]; echo $lname [1]; // End testing ?> <br>Login failed, bad username/password <? } Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/ Share on other sites More sharing options...
teng84 Posted October 5, 2007 Share Posted October 5, 2007 try this first and see the values print_r(mysql_fetch_array($sql_result)); Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363004 Share on other sites More sharing options...
Gibbs Posted October 5, 2007 Share Posted October 5, 2007 Nevermind. Can't keep up with gurus... Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363005 Share on other sites More sharing options...
teng84 Posted October 5, 2007 Share Posted October 5, 2007 Start by checking your query syntax? "WHERE 1"? What's that meant to achieve? yep what is where 1! but that will work although i find it useless thats working so let it be lol Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363009 Share on other sites More sharing options...
benjihana Posted October 5, 2007 Author Share Posted October 5, 2007 The output to that is as follows: Array ( [0] => johndoe [username] => johndoe [1] => thisismypass [password] => thisismypass ) Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363018 Share on other sites More sharing options...
benjihana Posted October 6, 2007 Author Share Posted October 6, 2007 The even more odd thing is whenever I manually assign a value to the $pass array, it still only outputs the first letter... $pass [0] = "test"; echo $pass [0]; That outputs 't'. Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363022 Share on other sites More sharing options...
marcus Posted October 6, 2007 Share Posted October 6, 2007 $pass = array(); $pass[] = "test"; echo $pass[0]; Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363030 Share on other sites More sharing options...
teng84 Posted October 6, 2007 Share Posted October 6, 2007 but base on the output above you get the real value try $value = mysql_fetch_array($sql_result); echo $value['username']; Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363031 Share on other sites More sharing options...
teng84 Posted October 6, 2007 Share Posted October 6, 2007 $pass = array(); $pass[] = "test"; echo $pass[0]; is there with $array[] =value and $array = array(); $array[] = value; ??? Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363033 Share on other sites More sharing options...
marcus Posted October 6, 2007 Share Posted October 6, 2007 $pass = array(); $pass[] = "test"; $pass[] = "pie"; foreach($pass AS $passs){ echo $passs . "<br>\n"; } I'm just declaring the variable as a predefined array. Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363038 Share on other sites More sharing options...
benjihana Posted October 6, 2007 Author Share Posted October 6, 2007 Pre-defining the array worked. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/72040-solved-only-sending-first-letter/#findComment-363054 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.