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 Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/ 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 Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/#findComment-528591 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'] . "';"; Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/#findComment-528592 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..... Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/#findComment-528674 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. Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/#findComment-528676 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 Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/#findComment-528677 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> Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/#findComment-528691 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 Link to comment https://forums.phpfreaks.com/topic/103194-solved-unexpected-t_variable/#findComment-528713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.