Page 1 of 1
PHP Unexpected T_STRING Line 23?
Posted: Fri Jul 03, 2009 1:44 pm
by cloudnyn3
Usually that parse error refers to incorrect syntax, but im REALLY not seeing what I'm doing wrong so if you could point it out or something a hint anything!!
Parse error: syntax error, unexpected T_STRING in /blah/blah/i/n/t/blah/html/php/checklogin.php on line 23
Code: Select all
<?php
//Database Information
$dbhost = "blah";
$dbname = "Administrator";
$dbuser = "Administrator";
$dbpass = "***********";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
//This below is the line with the problem and i don't see what i did wrong(it says 23 but I moved it down)
$query=“SELECT * FROM users WHERE username=’$username’ and password=’$password’”;
$result = mysql_query($query);
if (mysql_num_rows($result) !=1) {
$error = “Bad Login”;
include “/main_login.html”;
} else {
$_SESSION[‘username’] = “$username”;
include “test.hml
”;
}
?>
I believe my SQL is correct and i called it properly, all of my variables are correct I dunno whats wrong =/
Re: PHP Unexpected T_STRING Line 23?
Posted: Fri Jul 03, 2009 2:31 pm
by emix
characters are invalid
you must not use ’ - use ' instead
you must not use ” - use " instead
Code: Select all
session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);
//This below is the line with the problem and i don't see what i did wrong(it says 23 but I moved it down)
$query="SELECT * FROM users WHERE username='$username' and password='$password' ";
Re: PHP Unexpected T_STRING Line 23?
Posted: Fri Jul 03, 2009 4:18 pm
by cloudnyn3
Ok that was pretty stupid on my part, and Its fixed and the script works EXCEPT now i have another error, and one that I frequently get for some reason and when I fix this its with me not know how I did.
On line 27 the num_rows has an issue, and I've tried it several different ways but I don't know what it is, because I checked syntax, characters
Code: Select all
<?php
//Database Information
$dbhost = "Administrators1.db.4568545.hostedresource.com";
$dbname = "Administrators1";
$dbuser = "Administrators1";
$dbpass = "spackl3Ir0n";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
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 "../main_login.html";
} else {
$_SESSION['username'] = "$username";
include 'test.hml';
}
?>
Re: PHP Unexpected T_STRING Line 23?
Posted: Fri Jul 03, 2009 4:40 pm
by jackpf
Re: PHP Unexpected T_STRING Line 23?
Posted: Fri Jul 03, 2009 4:54 pm
by Eric!
Try this
Code: Select all
if (mysql_num_rows($result) < 1) {
$error = "Bad Login";
include "../main_login.html";
} else {
$_SESSION['username'] = "$username";
include 'test.hml';
}
Re: PHP Unexpected T_STRING Line 23?
Posted: Fri Jul 03, 2009 9:56 pm
by cloudnyn3
Ok So i applied the suggestions, but no matter the input the same outcome occurs, I think its a problem in the PHP but I could be wrong =/
it clears everything and gets to that if statement but ignores the else and uses the if.
even though its telling it that if rows = < 1 it still redirects me to the home page, even if the login is correct =/
So heres the updated code after I went through and made a few changes so it would do things differently but now its like it just doens't care what input it gets, it just uses
Code: Select all
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
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)
{
header("Location: http://blah.com.com/main_login.html");
}
else {
$_SESSION['username'] = "$username";
include 'test.html';
}
?>
Re: PHP Unexpected T_STRING Line 23?
Posted: Sat Jul 04, 2009 12:36 am
by requinix
Anybody notice the other smart quotes?
Code: Select all
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
Re: PHP Unexpected T_STRING Line 23?
Posted: Sat Jul 04, 2009 12:52 am
by cloudnyn3
tasairis wrote:Anybody notice the other smart quotes?
Code: Select all
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
I really don't know why my IDE does that, it uses characters it isn't supposed to use, like the majority of errors are caused by these crazy keyboard errors =/
But dude!! you have literally saved me sooo much trouble, i'm really a noob to PHP but I really should have noticed that >_<
but yeah, my site is completely functioning thanks to you!