S A N T A Posted April 28, 2008 Share Posted April 28, 2008 ok so i have this login that when you login it redirects you to the index page BUT on the index page there is suppose to display "Logout" instead of "Login" here the login code: <?php require("config.php"); session_start(); $db = mysql_connect($dbhost, $dbuser); mysql_select_db($dbdatabase, $db); if($_POST['submit']) { $sql = "SELECT * FROM logins WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';"; $result = mysql_query($sql); $numrows = mysql_num_rows($result); if($numrows == 1) { $row = mysql_fetch_assoc($result); session_register("USERNAME"); session_register("USERID"); $_SESSION['USERNAME'] = $row['username']; $_SESSION['USERID'] = $row['id']; header("Location: " . $config_basedir); } else { header("Location: " . $config_basedir . "/login.php?error=1"); } } else { //require("header.php"); if($_GET['error']) { echo "Incorrect login, please try again!"; } ?> <form action="<?php echo $SCRIPT_NAME ?>" method="post"> <table> <tr> <td>Username</td> <td><input type="text" name="username"</td> </td> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Login!"></td> </tr> </tr> </table> </form> <? } ?> <?php require("footer.php"); ?> here is the link code: <?php if(isset($_SESSION['USERNAME']) == TRUE) { echo "<a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a>"; } ?> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/103274-solved-login-not-working/ Share on other sites More sharing options...
Fadion Posted April 28, 2008 Share Posted April 28, 2008 Have u started the session with session_start() in the second page? Link to comment https://forums.phpfreaks.com/topic/103274-solved-login-not-working/#findComment-528921 Share on other sites More sharing options...
S A N T A Posted April 28, 2008 Author Share Posted April 28, 2008 yes i have Link to comment https://forums.phpfreaks.com/topic/103274-solved-login-not-working/#findComment-528924 Share on other sites More sharing options...
Rohan Shenoy Posted April 28, 2008 Share Posted April 28, 2008 Are you getting any error message? mysql_connect($dbhost, $dbuser); Typically, mysql_connect() should pass one more argument about the db password. Does your db have a password and you are not supplying it? PS:if your db doesn't have a password, then its file to have only 2 arguments. Link to comment https://forums.phpfreaks.com/topic/103274-solved-login-not-working/#findComment-528927 Share on other sites More sharing options...
S A N T A Posted April 28, 2008 Author Share Posted April 28, 2008 EDIT: Sorry i was being stupid and forgot to put session_start(); in the index page Link to comment https://forums.phpfreaks.com/topic/103274-solved-login-not-working/#findComment-528928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.