erikn68 Posted March 16, 2012 Share Posted March 16, 2012 I am getting the error when I try to login. Here is my login.php code error message: Parse error: syntax error, unexpected T_STRING in /home/webspace/public_html/Eri $dbhost = "localhost"; $dbname = "webspace_eriknel1"; $dbuser = "webspace_er5"; $dbpass = "c6b7s9t1"; //Connect to database <?php mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); session_start(); $username = $_POST[‘username’]; $password = md5($_POST[‘password’]); $query = select from users where username=’$username’ and password=’$password’”; $result = mysql_query($query); if (mysql_num_rows($result) != 1) { $error = “Bad Login”; include “login.html”; } else { $_SESSION[‘username’] = “$username”; include “memberspage.php”; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/ Share on other sites More sharing options...
Muddy_Funster Posted March 16, 2012 Share Posted March 16, 2012 session_start(); needs to go at the very top of your page, just after the <?php line. $query = select from users where username=’$username’ and password=’$password’”; has no opening double quote so your sting is totaly malformed and running into the rest of your code. $dbpass = "c6b7s9t1"; Needs to be changed NOW! Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328101 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 $dbpass = ""; Needs to be changed NOW! You should probably remove it from your quote too. EDIT: Derp, brainfart. Thought you meant changed from his post, but I suppose he ought to change it on his server. Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328115 Share on other sites More sharing options...
Muddy_Funster Posted March 16, 2012 Share Posted March 16, 2012 I ment in the actual database, there were at least 8 views of this page prior to my posting and too much time has gone by for me to edit now :-\ Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328126 Share on other sites More sharing options...
erikn68 Posted March 16, 2012 Author Share Posted March 16, 2012 I am getting the same error but it is with this line. $query = "select" from users where username=’$username’ and password=’$password’”; Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328148 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 Should be $query = "select * from users where username=’$username’ and password=’$password’”; Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328150 Share on other sites More sharing options...
erikn68 Posted March 16, 2012 Author Share Posted March 16, 2012 Another error Parse error: syntax error, unexpected $end in /home/webspace/public_html/Erik.Nelson/login.php on line 32 This is line 32 ?> All of the code, but I removed the db password for the forum $dbhost = "localhost"; $dbname = "webspace_eriknel1"; $dbuser = "webspace_er5"; $dbpass = ""; //Connect to database <?php session_start(); mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $username = $_POST[‘username’]; $password = md5($_POST[‘password’]); $query = "select * from users where username=’$username’ and password=’$password’”; $result = mysql_query($query); if (mysql_num_rows($result) != 1) { $error = “Bad Login”; include “login.html”; } else { $_SESSION[‘username’] = “$username”; include “memberspage.php”; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328160 Share on other sites More sharing options...
mikosiko Posted March 16, 2012 Share Posted March 16, 2012 @OP: Seems that you are using several smart-quotes and apostrophes instead of regular double or single quotes in your code $username = $_POST[‘username’]; $password = md5($_POST[‘password’]); $query = "select * from users where username=’$username’ and password=’$password’”; $result = mysql_query($query); if (mysql_num_rows($result) != 1) { $error = “Bad Login”; include “login.html”; } else { $_SESSION[‘username’] = “$username”; include “memberspage.php”; Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328162 Share on other sites More sharing options...
erikn68 Posted March 16, 2012 Author Share Posted March 16, 2012 error = Parse error: syntax error, unexpected T_STRING in /home/webspace/public_html/Erik.Nelson/login.php on line 33 Line 33 = ini_set("display_errors", 1); full code except dbpass $dbhost = "localhost"; $dbname = "webspace_eriknel1"; $dbuser = "webspace_er5"; $dbpass = ""; //Connect to database <?php session_start(); mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $username = $_POST[‘username’]; $password = md5($_POST[‘password’]); $query = "select * from users where username=’$username’ and password=’$password’”; $result = mysql_query($query); if (mysql_num_rows($result) != 1) { $error = “Bad Login”; include “login.html”; } else { $_SESSION[‘username’] = “$username”; include “memberspage.php”; } error_reporting(E_ALL); ini_set("display_errors", 1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328169 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 As mikosiko pointed out, you need to change all those wonky double quotes and apostrophes to real double quotes and single quotes. Also, the error reporting stuff should be at the very top of your script. EDIT: And unless you are running PHP5.4, that should be error_reporting(E_ALL | E_STRICT); Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328171 Share on other sites More sharing options...
erikn68 Posted March 16, 2012 Author Share Posted March 16, 2012 I am getting error on this code: $error = "Bad Login"; include "login.html"; I switched the quotes and apostrophes Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328182 Share on other sites More sharing options...
mikosiko Posted March 16, 2012 Share Posted March 16, 2012 and the error is?.... crystal ball is not available today. to short this out a bit... here .... just copy/paste..... and answer/fix the commented questions <?php error_reporting(E_ALL); ini_set("display_errors", 1); session_start(); $dbhost = "localhost"; $dbname = "webspace_eriknel1"; $dbuser = "webspace_er5"; $dbpass = ""; mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); // you MUST sanitize your input $username = $_POST['username']; $password = md5($_POST['password']); $query = "select * from users where username='$username' and password='$password'"; $result = mysql_query($query); if (mysql_num_rows($result) != 1) { $error = "Bad Login"; // What are yuu trying to do here... redirect to the user to the login page? // For that you must use header() not include() include "login.html"; } else { $_SESSION['username'] = "$username"; // What are yuu trying to do here... redirect to the user to the members page? // For that you must use header() not include() include "memberspage.php"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259063-parse-error-syntax-error-unexpected-t_string-in-homewebspacepublic_htmleri/#findComment-1328187 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.