HDFilmMaker2112 Posted June 20, 2011 Share Posted June 20, 2011 I'm looking to know I could reduce this a bit? I'm thinking that counting the number of rows returned and comparing the password and username typed in matches the one selected from the database is useless, as the select query itself should give me that info. If it returns a row then clearly it's the correct information. So should I remove this?: $row=mysql_fetch_row($result); $usernamec=$row[0]; $passwordc=$row[4]; // Register $myusername, $mypassword and redirect to file if($myusername==$usernamec && $mypassword==$passwordc){ <?php // username and password sent from form $myusername=sanitize($_POST['username']); $mypassword=kam3(sanitize($_POST['password'])); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' AND password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ $row=mysql_fetch_row($result); $usernamec=$row[0]; $passwordc=$row[4]; // Register $myusername, $mypassword and redirect to file if($myusername==$usernamec && $mypassword==$passwordc){ session_start(); $_SESSION['myusername2']=$myusername; $_SESSION['mypassword2']=$mypassword; header("location:index.php?usercp"); } } else{ if($usernamec!=$myusername || !isset($myusername) || $passwordc!=$mypassword){ $u2="0"; } header('Location:./index.php?u2='.$u2.''); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/239886-looking-for-review-of-script/ Share on other sites More sharing options...
trq Posted June 20, 2011 Share Posted June 20, 2011 You are absolutely correct. Just check mysql_num_rows has at least one record. Quote Link to comment https://forums.phpfreaks.com/topic/239886-looking-for-review-of-script/#findComment-1232213 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 20, 2011 Author Share Posted June 20, 2011 Thanks. Half asleep here, didn't want to screw something up without knowing it would work. Quote Link to comment https://forums.phpfreaks.com/topic/239886-looking-for-review-of-script/#findComment-1232225 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.