PHP Unexpected T_STRING Line 23?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cloudnyn3
Forum Newbie
Posts: 7
Joined: Fri Jun 26, 2009 11:12 am

PHP Unexpected T_STRING Line 23?

Post 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 =/
User avatar
emix
Forum Newbie
Posts: 8
Joined: Mon Jun 22, 2009 10:32 am
Location: Poland

Re: PHP Unexpected T_STRING Line 23?

Post 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' ";
 
cloudnyn3
Forum Newbie
Posts: 7
Joined: Fri Jun 26, 2009 11:12 am

Re: PHP Unexpected T_STRING Line 23?

Post 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';
}
 
?>
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP Unexpected T_STRING Line 23?

Post by jackpf »

Put

Code: Select all

or die(mysql_error());
after the query.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: PHP Unexpected T_STRING Line 23?

Post 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';
}
 
cloudnyn3
Forum Newbie
Posts: 7
Joined: Fri Jun 26, 2009 11:12 am

Re: PHP Unexpected T_STRING Line 23?

Post 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';
}
 
?>
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Unexpected T_STRING Line 23?

Post by requinix »

Anybody notice the other smart quotes?

Code: Select all

$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
cloudnyn3
Forum Newbie
Posts: 7
Joined: Fri Jun 26, 2009 11:12 am

Re: PHP Unexpected T_STRING Line 23?

Post 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!
Post Reply