S A N T A Posted April 28, 2008 Share Posted April 28, 2008 Ok so for a blog I'm making I'm working on a login so i tried to get it to say "Incorrect login blah,blah,blah" but i get the error: Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\login.php on line 28 from this 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"); } [b]else {[/b] 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"); ?> The letters in bold is line 28 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/103222-solved-unexpected-t_else/ Share on other sites More sharing options...
zenag Posted April 28, 2008 Share Posted April 28, 2008 it must be like this...... check it out.... 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 . "/gane/error.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"); ?> Link to comment https://forums.phpfreaks.com/topic/103222-solved-unexpected-t_else/#findComment-528717 Share on other sites More sharing options...
zenag Posted April 28, 2008 Share Posted April 28, 2008 change this it to urs location.... header("Location: " . $config_basedir . "/gane/error.php?error=1"); as ... header("Location: " . $config_basedir . /error.php?error=1"); Link to comment https://forums.phpfreaks.com/topic/103222-solved-unexpected-t_else/#findComment-528719 Share on other sites More sharing options...
soycharliente Posted April 28, 2008 Share Posted April 28, 2008 You have two else statements in a row. Link to comment https://forums.phpfreaks.com/topic/103222-solved-unexpected-t_else/#findComment-528720 Share on other sites More sharing options...
GameYin Posted April 28, 2008 Share Posted April 28, 2008 if else = fine. if else else = bad. As a alternative, try: if elseif else. You can have all the elseif's you want. Problem is, you have to think of a conditional statement Link to comment https://forums.phpfreaks.com/topic/103222-solved-unexpected-t_else/#findComment-528786 Share on other sites More sharing options...
DarkWater Posted April 28, 2008 Share Posted April 28, 2008 It's because you forgot a curly brace before you put the next else statement. Link to comment https://forums.phpfreaks.com/topic/103222-solved-unexpected-t_else/#findComment-528794 Share on other sites More sharing options...
soycharliente Posted April 28, 2008 Share Posted April 28, 2008 I see the brace Link to comment https://forums.phpfreaks.com/topic/103222-solved-unexpected-t_else/#findComment-528919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.