slj90 Posted December 11, 2009 Share Posted December 11, 2009 Hello, I am trying to make a login form, I have a login form page and an action page, here is the code from the action page: <?php include "connection2.php"; ?> <?php session_start(); // Collect data from form and save in variables //See if any info was submitted $Username = $_GET['Username']; //Clean data - trim space $Username = trim ( $Username); //Check its ok - if not then add an error message to the error string if (empty($Username)) $errorString = $errorString."<br>Please supply Username."; //See if any info was submitted $Password = $_GET['Password']; //Clean data - trim space $Password = trim ( $Password); //Check its ok - if not then add an error message to the error string if (empty($Password)) $errorString = $errorString."<br>Please supply Password."; // Query to search the user table $query= "SELECT * FROM Users WHERE Username='$Username' AND Password='$Password'" // Run query through connection $result = mysql_query ($query); // Check result of query // if rows found set authenticated user to the user name entered if (mysql_num_rows($result) > 0) { $_SESSION["authenticatedUser"] = $Username; // Relocate to the logged-in page header("Location: loggedon.php"); } else // login failed redirect back to login page with error message { $_SESSION["message"] = "Could not connect as $Username " ; header("Location: login.php"); } ?> At the moment, I get the error 'syntax error, unexpected T_VARIABLE' on line 27 ($result = mysql_query ($query); ) Can you see anything wrong? Thank you for your help Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/ Share on other sites More sharing options...
rajivgonsalves Posted December 11, 2009 Share Posted December 11, 2009 your missing a semicolin again at the previous line Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/#findComment-975274 Share on other sites More sharing options...
Deoctor Posted December 11, 2009 Share Posted December 11, 2009 change this to $query= "SELECT * FROM Users WHERE Username='$Username' AND Password='$Password'" $query= "SELECT * FROM Users WHERE Username='$Username' AND Password='$Password'"; Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/#findComment-975276 Share on other sites More sharing options...
slj90 Posted December 11, 2009 Author Share Posted December 11, 2009 Thanks alot! That has got rid of that error but now I have the following... Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at H:\xampp\xampp\htdocs\loginAction.php:5) in H:\xampp\xampp\htdocs\loginAction.php on line 6 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at H:\xampp\xampp\htdocs\loginAction.php:5) in H:\xampp\xampp\htdocs\loginAction.php on line 6 Warning: Cannot modify header information - headers already sent by (output started at H:\xampp\xampp\htdocs\loginAction.php:5) in H:\xampp\xampp\htdocs\loginAction.php on line 35 Any suggestions ? Thanks Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/#findComment-975282 Share on other sites More sharing options...
Deoctor Posted December 11, 2009 Share Posted December 11, 2009 in the connection2.php u might have already passed a session, so remove the session from here i think that would help Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/#findComment-975286 Share on other sites More sharing options...
slj90 Posted December 11, 2009 Author Share Posted December 11, 2009 connection2.php only contains the following code... <?php $connection = mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("users", $connection) or die(mysql_error()); ?> so i don't think that's the problem? any other ideas? your help is much appreciated! thanks Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/#findComment-975287 Share on other sites More sharing options...
rajivgonsalves Posted December 11, 2009 Share Posted December 11, 2009 put your session_start over there. and remove it from all the other files you've put it in <?php session_start(); $connection = mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("users", $connection) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/#findComment-975290 Share on other sites More sharing options...
slj90 Posted December 11, 2009 Author Share Posted December 11, 2009 I seemed to have solved the problem by removing blank lines before and after <?php... ?> Thanks for your help and fast responses.. My log in form now works! Link to comment https://forums.phpfreaks.com/topic/184746-login-form-help/#findComment-975293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.