zero_ZX Posted November 13, 2007 Share Posted November 13, 2007 hi every1!! I know a very little about php, but not much, so i though this was a great place to start ^^ (1 post) I took a look into this script and wondered why it didnt work.. i couldn't find anything which was wrong to me, but if i enter username, ill get to step2, and then im prompted to enter username again... Also i have some md5 problems but isnt the syntax $md5 ? well if you can find any bugs, please inform me ^^ thank you very much, its really appriciated. <?php // first, let's see what step they're on... $step = $_GET['step']; // if a user is allready logged in, and he's not trying to log out, he has no bussiness on this file if ( $step != 'logout' && $_SESSION['login'] === TRUE ) { $step = 'loggedin'; } switch($step) { //if step is not defined in the url, then they're going to this step default: case 'one': // ask for username echo '<form action="login.php?step=2" method="POST"> Username : <input type="text" name="username"> <br> <input type="submit" value="submit"> </form>'; break; case 'two': // get username from step 1 $username = $_POST['username']; // now ask for the password echo '<form action="login.php?step=3" method="POST"> Password : <input type="password" name="password"> <input type="hidden" name="username" value="'.$username.'"> <input type="submit" value="submit">'; break; case 'three': // get username and password from step two $username = $_POST['username']; $password = $_POST['password']; // connect to database, however you do it.. i use dbconnect(); // define query $sql = "SELECT username, password FROM users WHERE username =".$username." AND password =".$password."GROUP BY username"; if ( !$results = mysql_query($sql)) { die('Username or password are incorrect!'); } else { $_SESSION['data'] = mysql_fetch_assoc($results); $_SESSION['login'] = TRUE; } break; case 'loggedin': echo "You are allready logged in."; break; case 'logout': if ( $_SESSION['login'] === TRUE ) { if ( isset($_COOKIE[session_name()]) ) { setcookie(session_name(), '', time()-42000, '/'); } foreach ( $_SESSION as $k=>$v ) { unset($_SESSION[$k]); } session_destroy(); echo "You've successfully logged out!"; } break; } ?>` Quote Link to comment Share on other sites More sharing options...
smithygotlost Posted November 13, 2007 Share Posted November 13, 2007 i was looking at your databse connect ect as this could be what is going wrong im presuming that dbconnect(); links to a database connect cause i have looked into this connect and it seems to cause problems :S is this your full code ? try this <?php // first, let's see what step they're on... $step = $_GET['step']; // if a user is allready logged in, and he's not trying to log out, he has no bussiness on this file if ( $step != 'logout' && $_SESSION['login'] === TRUE ) { $step = 'loggedin'; } switch($step) { //if step is not defined in the url, then they're going to this step default: case 'one': // ask for username echo '<form action="login.php?step=2" method="POST"> Username : <input type="text" name="username"> <input type="submit" value="submit"> </form>'; break; case 'two': // get username from step 1 $username = $_POST['username']; // now ask for the password echo '<form action="login.php?step=3" method="POST"> Password : <input type="password" name="password"> <input type="hidden" name="username" value="'.$username.'"> <input type="submit" value="submit">'; break; case 'three': // get username and password from step two $username = $_POST['username']; $password = $_POST['password']; //Set up all yor paramaters for connection $db = new DbConnect "localhost","user","password","database",$error_reporting=false,$persistent=false); //Open the connection to your database $db->open() or die($db->error()); //Query the database now the connection has been made $sql->query("SELECT username, password FROM users WHERE username =".$username." AND password") or die($db->error()); else { $_SESSION['data'] = mysql_fetch_assoc($results); $_SESSION['login'] = TRUE; } break; case 'loggedin': echo "You are allready logged in."; break; case 'logout': if ( $_SESSION['login'] === TRUE ) { if ( isset($_COOKIE[session_name()]) ) { setcookie(session_name(), '', time()-42000, '/'); } foreach ( $_SESSION as $k=>$v ) { unset($_SESSION[$k]); } session_destroy(); echo "You've successfully logged out!"; } break; } ?> Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted November 14, 2007 Author Share Posted November 14, 2007 for now, this is my full code.. but yea it will be bigger with more security and support for md5.. i just think ill need to start some where, and i though this code looked easy. Thanks alot for your help its very appriciated!!! ill return later with ever this fixed or not, once again thank you ^^ Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted November 14, 2007 Author Share Posted November 14, 2007 $db = new DbConnect "localhost","user","password","database",$error_reporting=false,$persistent=false); something is wrong here Quote Link to comment Share on other sites More sharing options...
centerwork Posted November 14, 2007 Share Posted November 14, 2007 Your <form> is beening submited with # like 2 or 3. Your switch cases are using 'two' or 'three'. Change your cases to '2' and '3' and your code should work fine. Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted November 14, 2007 Author Share Posted November 14, 2007 oh it works now :D:D:D i just have to take a look into the dbconnect, but ill figure that out myself (for now) ^^ thanks alot guys!! marked as solved. Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted November 15, 2007 Author Share Posted November 15, 2007 hm well, topic is not solved any way.. heres my code: (and my error is:unexpected t_case in ..... on line 64 <?php // first, let's see what step they're on... $step = $_GET['step']; // if a user is allready logged in, and he's not trying to log out, he has no bussiness on this file if ( $step != 'logout' && $_SESSION['login'] === TRUE ) { $step = 'loggedin'; } switch($step) { //if step is not defined in the url, then they're going to this step default: case '1': // ask for username echo '<form action="login.php?step=2" method="POST"> Username : <input type="text" name="username"> <input type="submit" value="submit"> </form>'; break; case '2': // get username from step 1 $username = $_POST['username']; // now ask for the password echo '<form action="login.php?step=3" method="POST"> Password : <input type="password" name="password"> <input type="hidden" name="username" value="'.$username.'"> <input type="submit" value="submit">'; break; case '3': // get username and password from step two $username = $_POST['username']; $password = $_POST['password']; //Set up all yor paramaters for connection $db = new DbConnect("localhost","root","","test-login",$error_reporting=false,$persistent=false); //Open the connection to your database $db->open() or die($db->error()); //Query the database now the connection has been made $sql->query("SELECT username, password FROM users WHERE username =".$username." AND password") or die($db->error()); $_SESSION['data'] = mysql_fetch_assoc($results); $_SESSION['login'] = TRUE; } break; case 'logout': if ( $_SESSION['login'] === TRUE ) { if ( isset($_COOKIE[session_name()]) ) { setcookie(session_name(), '', time()-42000, '/'); } foreach ( $_SESSION as $k=>$v ) { unset($_SESSION[$k]); } session_destroy(); echo "You've successfully logged out!"; } break; } ?> Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted November 20, 2007 Author Share Posted November 20, 2007 bump Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 20, 2007 Share Posted November 20, 2007 Could it be the " } " on line 58, doesn't look like it should be there to me. It's after the following: <?php $_SESSION['data'] = mysql_fetch_assoc($results); $_SESSION['login'] = TRUE; ?> Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted November 22, 2007 Author Share Posted November 22, 2007 unexpected t_case at line 59 Quote Link to comment 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.