php_novice2007 Posted April 3, 2007 Share Posted April 3, 2007 Hi, I added php sessions to my code and now my javascripts on loginForm.php doesn't work!.. It goes straight to invalid login if say I didn't type in anything and just pressed submit.. it was working before I added the session stuff... Why does it not do my javascript now.. <html> <head> <script type="text/javascript"> function check_myform1() { if((myform1.userid.value.length == 0)) { alert("Please enter user id"); myform1.userid.focus(); return false; } if((myform1.password.value.length == 0)) { alert("Pleas enter password"); myform1.password.focus(); return false; } return true; } </script> </head> <body> <br> <form name="myform1" action='loginck.php' method=post onSubmit="return check_myform1();"> <table> <tr><td>Login Name</td><td><input type ='text' name='login' ></td></tr> <tr><td>Password</td><td><input type ='password' name='password' ></td></tr> <tr><td><input type='submit' value='Submit'><input type='reset' value='Reset'></td> </tr> </table></form> </body> </html> loginck.php: <?php if (isset($_POST['login']) && isset($_POST['password'])) { $userid = $_POST['login']; $passWord = $_POST['password']; $database="red1"; $dbtable = "users"; $link=mysql_connect("localhost", root, abcd) or die("Cannot connect to database"); //select database @mysql_select_db($database) or die("Unable to select database"); //Look for a record with matching user_id, not case sensitive $query="SELECT * FROM $dbtable WHERE user_id = '$userid'"; $result=mysql_query($query, $link) or die("Unable to load selected table"); //find out how many rows there are in the database $num=mysql_num_rows($result); mysql_close($link) or die("Unable to close database"); if ($num < 1) { // no matching user_id echo "Invalid Login details <br> Please <a href=loginForm.html>go back</a> and try again"; } else { // check the user_id, case sensitive, and password $i=0; $match = 0; $unitsViewable; while ($i < $num) { // incase there are two user_id which are the same letter wise but not case wise $nameInDB = mysql_result($result,$i,"user_id"); $passInDB = mysql_result($result,$i,"passWord"); $unitsViewable = mysql_result($result,$i,"units"); if ( strcmp($userid,$nameInDB)==0 && strcmp($passWord,$passInDB)==0 ) { $match = 1; break; } $i++; } if ($match == 0) { echo "Invalid Login details <br> Please <a href=loginForm.html>go back</a> and try again"; } else { session_start(); // start up PHP session! session_register('userid'); $_SESSION['user_id'] = $userid; $_SESSION['unitsViewable'] = $unitsViewable; echo "Welcome $userid!!<br><br>Please click <a href=secureMenu.php>here </a> to go to the main menu page..."; } } } else { //user shouldn't be on this page without inputing a username and a password echo "here"; //header( "http://127.0.0.1/thesis1/loginForm.html" ); } ?> Please help.. Link to comment https://forums.phpfreaks.com/topic/45409-php-sessions/ Share on other sites More sharing options...
tauchai83 Posted April 3, 2007 Share Posted April 3, 2007 don be worry. If your javascript do not work...you could do validation using php... if( $password==''){ echo "plese enter your password!"; } Link to comment https://forums.phpfreaks.com/topic/45409-php-sessions/#findComment-220522 Share on other sites More sharing options...
php_novice2007 Posted April 4, 2007 Author Share Posted April 4, 2007 I fixed the javascript now I had "myform1.userid.value.length" whereas it should've been login.value.length instead.. I have a new question... for my loginck.php, if I entered a correct user name and password and a session is started, I get a php warning.. what does this mean? Is my program only working because it is a fluke? My warning is: Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0 The code for loginck.php is same as above.. I think its very weird how I can do session_register('userid'); Shouldn't userid be $userid? It doesn't work when I put $userid. Also doesn't work if I put login.. what is php actually remembering?... Thanks! Link to comment https://forums.phpfreaks.com/topic/45409-php-sessions/#findComment-221097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.