S A N T A Posted April 27, 2008 Share Posted April 27, 2008 I am working on a blog and this is the login script but i seem to be getting the error: Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\login.php on line 6 this is the 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"); } ?> <div id="main"> <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> </div> Thanks in advance EDIT: Just so you know the require("config.php") and the other 2 are NOT the problem Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 27, 2008 Share Posted April 27, 2008 you need to put a dollar sign '$' in front of each variable line 6 should start with $sql rather then sql Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 27, 2008 Share Posted April 27, 2008 $sql = "SELECT * FROM logins WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';"; Quote Link to comment Share on other sites More sharing options...
S A N T A Posted April 28, 2008 Author Share Posted April 28, 2008 i still have the same error..... Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 28, 2008 Share Posted April 28, 2008 Could you show us the the updated code ( that includes the bugfix we mentioned ), the error message from the updated code, and highlight or point out which line that error messages is refering to. Quote Link to comment Share on other sites More sharing options...
S A N T A Posted April 28, 2008 Author Share Posted April 28, 2008 <?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"); } ?> <div id="main"> <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> </div> thats the code Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\login.php on line 6 thats the error $db = mysql_connect($dbhost, $dbuser); thats line 6 Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 28, 2008 Share Posted April 28, 2008 Cleaned up some syntax errors. <?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"); } ?> <div id="main"> <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> </div> Quote Link to comment Share on other sites More sharing options...
S A N T A Posted April 28, 2008 Author Share Posted April 28, 2008 Thanks man you rock 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.