PHP forum

Parse error making me insane!

Feb 16, 2010 12:33 am
Jason

Parse error: syntax error, unexpected T_VARIABLE in /home/henomel6/
public_html/post/checklogin.php on line 24

ok, loving php so far. but i cannot for the life of me figure out what
is causing this.

code below. i've tried for about an hour to debug this.

<?php
$host="localhost"; // Host name
$username="mySQLuser"; // Mysql username
$password="mySQLpw"; // Mysql password
$db_name="myDBname"; // Database name
$tbl_name="blog"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot
connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$user=$_POST['user'];
$pass=$_POST['pass'];

// To protect MySQL injection (more detail about MySQL injection)
$user = stripslashes($user);
$pass = stripslashes($pass);
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);


$sql="SELECT * FROM '$tbl_name' WHERE User='$user' and Pass='$pass';"
$result=mysql_query($sql); //THIS IS LINE 24

//echo $sql;

// Mysql_num_row is counting table row
//$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1
row

/*if($count==1){
// Register $myusername, $mypassword and redirect to file
"login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}*/
?>

Feb 16, 2010 12:35 am
Jason
Re: parse error making me insane!

moment of clarity. line 23 did not have a closing semi-colon.

:smacks self on head:


Feb 16, 2010 1:10 am
Mike Moum
Re: parse error making me insane!

I think you have you double quote and semicolon transposed. You don't
need a semicolon at the end of an sql string when using mysql_query.

Mike

jason wrote:
> Parse error: syntax error, unexpected T_VARIABLE in /home/henomel6/
> public_html/post/checklogin.php on line 24
>
> ok, loving php so far. but i cannot for the life of me figure out what
> is causing this.
>
> code below. i've tried for about an hour to debug this.
>
> <?php
> $host="localhost"; // Host name
> $username="mySQLuser"; // Mysql username
> $password="mySQLpw"; // Mysql password
> $db_name="myDBname"; // Database name
> $tbl_name="blog"; // Table name
>
> // Connect to server and select databse.
> mysql_connect("$host", "$username", "$password")or die("cannot
> connect");
> mysql_select_db("$db_name")or die("cannot select DB");
>
> // username and password sent from form
> $user=$_POST['user'];
> $pass=$_POST['pass'];
>
> // To protect MySQL injection (more detail about MySQL injection)
> $user = stripslashes($user);
> $pass = stripslashes($pass);
> $user = mysql_real_escape_string($user);
> $pass = mysql_real_escape_string($pass);
>
>
> $sql="SELECT * FROM '$tbl_name' WHERE User='$user' and Pass='$pass';"
> $result=mysql_query($sql); //THIS IS LINE 24
>
> //echo $sql;
>
> // Mysql_num_row is counting table row
> //$count=mysql_num_rows($result);
> // If result matched $myusername and $mypassword, table row must be 1
> row
>
> /*if($count==1){
> // Register $myusername, $mypassword and redirect to file
> "login_success.php"
> session_register("myusername");
> session_register("mypassword");
> header("location:login_success.php");
> }
> else {
> echo "Wrong Username or Password";
> }*/
> ?>


Feb 16, 2010 6:29 am
Arto Viitanen
Re: parse error making me insane!

16.2.2010 3:10, Mike Moum wrote:
> I think you have you double quote and semicolon transposed. You don't
> need a semicolon at the end of an sql string when using mysql_query.
>
>
>>
>> $sql="SELECT * FROM '$tbl_name' WHERE User='$user' and Pass='$pass';"
>> $result=mysql_query($sql); //THIS IS LINE 24
>>

Also I think Mysql does not like table names to have hyphens; the query
would be

SELECT * FROM 'blob' WHERE User='something' and Pass='something'

--
Arto Viitanen




Previous Thread: Zero division not caught
Next Thread: Comparing Arrays Question - I can't figure out what function to use!

Related Forum Topics
Parse error: syntax error, unexpected T_VARIABLE
at line :
public static $JAR=$_SERVER['DOCUMENT_ROOT'] .
'/AB2Html/Builder/saxon9he.jar';

i got the error :
Parse error: syntax error, unexpected T_VARIABLE

this is inside a class.

if i test the above line apart, in another script, outside any class, i
get NO error.

then, is...
Why do I get a parse error?
When trying to place a simple form tag just after the "IF", I wind up
getting a parse error.

Parse error: syntax error, unexpected '<' in

yet if I insert something like print $i; all is well.


Also I would like to know how not to print the "is wrong" when $answr is
null upon page...
PHP/MYSQL Parse Error
I'm trying to learn PHP/MYSQL and I keep getting an error when trying
to enter data into MYSQL.

Here is the form:


<form action="insert.php" method="post">
FirstName: <input type="text" name="FirstName"><br>
LastName: <input type="text" name="LastName"><br>
Age: <input type="text"...
Please help with this presumably simple parse error
I am trying to extract post metadata from wordpress custom field, with
the ID withdrawals. From there I am trying to determine if one spesial
withdrawal value is equal to one determined image, the image is
supposed to be displayed with a link.
But I get a parse error on the last line...
What's wrong with this array? Parse error
Just comparing two arrays, I get a parse error with one.

I have the following two items:
$desserts[1]="pie";
echo $desserts[1]
$QandA[1]="who?";
echo $QandA[1]

I get:
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in
C:\Users\~~\AppData\Local\Temp\prev2~.php on...
Undefined index or parse error: take your pick
I have this line in a class script:
$this->message .= "To: $row['msg_to']";

(actually the line is longer (see below) but this section shows
the problem)

If I omit the ticks around msg_to I get this notice:
Notice: Undefined index: msg_to in
/var/www/MP2010-v2/classes/cMail.php on line...
Pagination driving me insane
Hi All,

I have a page which displays accounts. On the page there are three
search options:

1. sort by newest members first;
2. search by country;
3. search by name;

There is a limit of 10 accounts per page. If the query returns more
than 10 records I have to browse to the next...
Making strings filesystem compliant
Hi group,

I'm managing a website where users can upload files to songs, and the
filenames are generated from the song's title and composer. On another page
there's a form that allows to upload a file with a remark. And this remark
could contain any character.

All those information for...
Best PHP Web Application for making a Social Networking Community

To try my hand on Webmaking for the first time and to create a a small
social networking community I've downloaded this ampps 'Softaculous
AMPPS' (http://www.softaculous.com/ampps/). But with little php
knowledge I don't which out of these Social Networking Application
provided by ampps would be...
How to parse url?
Hi

php5

I have a form I want to submit to an extern url (not a page on my site),
that page I submit to will show some status values on how the submit went.
Show details like status etc..

But I want the user to stay on the same page as the form, so they submit
must happend in the...