Page 1 of 1

wierd error ... can someone explain

Posted: Thu Sep 11, 2003 1:23 pm
by zick
i've been getting a wierd error ... and it's not explained vey well in the php manual

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/http/public_html/acs/index.php on line 23

now i'm not sure what all T_STRING thing is all about, but line 23 is commented out, so how can i have an error there. i copied the line here:

Code: Select all

// $_SESSIONї'a'] = $a; // no users by provided name available
now i got this error one other time when i was setting a $_SESSION variable and i got rid of it by setting it like so:

Code: Select all

$_SESSIONї'a'] = $a;
instead of

Code: Select all

$_SESSIONї'a'] = false;
and i set $a to false.

does anyone know what this error means so i know how to avoid it next time.

Posted: Thu Sep 11, 2003 1:34 pm
by JAM
A thought; are you missing a ; in any previous line?

Code: Select all

// example
<?php
$foo = 'bar'
$bar = 'foo';
// Opps, forgot the ; on the first row. Makes it think I'm...
$foo = 'bar' $bar = 'foo'; // ...which is bad.
?>
It's abit tricky sometimes as the line with the error not allways needs to refer to the actual error (typos, chars missing) but where it actually breaks so to speak.

Posted: Thu Sep 11, 2003 1:40 pm
by zick
i should have done this but heres the entire page:

Code: Select all

<?php

$uid = $_POST&#1111;'un']; // username from form
$upw = $_POST&#1111;'ps']; // password from form
$hst = "localhost";
$usr = "acs"; // db connect user
$pwd = "acs"; // db connect pass
$a = 0;

echo $uid;
echo $upw;

// session_start();

error_reporting(0);
$lid = mysql_connect($hst, $usr, $pwd);

$qry = "select * from user where name = '$uid';
$rsl = mysql_query($qry);


if (mysql_num_rows ($rsl) == 0) &#123;
	// $_SESSION&#1111;'a'] = $a; // no users by provided name available
	echo "user doesn't exist ...";
&#125; else &#123;
	echo "user exists ...";
	while ($qdt = mysql_fetch_row($rsl)) &#123;
		if ($qdt&#1111;2] == $upw) &#123; // passwords match
			$a = 1;
			// $_SESSION&#1111;'a'] = $a;
			echo "& passwords match.";
		&#125; else &#123; // username exists, but password is wrong
			// $_SESSION&#1111;'a'] = $a;
			echo "& passwords don't match ...";
		&#125;

	&#125;
&#125;

?>
*i did just realize that i hadn't selected a database, but that shouldn't have caused any problems

Posted: Thu Sep 11, 2003 1:43 pm
by zick
i also took out the lines regarding sessions (not commented, but removed entirely) and it kinda worked ... i think it has something to do with sessions.

Posted: Thu Sep 11, 2003 1:49 pm
by JAM

Code: Select all

$qry = "select * from user where name = '$uid';
You are missing a " at the end.

Code: Select all

$qry = "select * from user where name = '$uid'";

Posted: Thu Sep 11, 2003 1:51 pm
by phice
Where's your session_start(); ?
:D

Edit:
ah, ha! Found it, but it needs to be on the very first line if you use that function.

code:

Code: Select all

<?php
session_start();
$uid = $_POST['un']; // username from form 
$upw = $_POST['ps']; // password from form 
$hst = "localhost"; 
$usr = "acs"; // db connect user 
$pwd = "acs"; // db connect pass 
$a = 0; 

echo $uid; 
echo $upw; 

error_reporting(0); 
$lid = mysql_connect($hst, $usr, $pwd); 

$qry = "select * from user where name = '$uid'; 
$rsl = mysql_query($qry); 


if (mysql_num_rows ($rsl) == 0) { 
   $_SESSION['a'] = $a; // no users by provided name available 
   echo "user doesn't exist ..."; 
} else { 
   echo "user exists ..."; 
   while ($qdt = mysql_fetch_row($rsl)) { 
      if ($qdt[2] == $upw) { // passwords match 
         $a = 1; 
         $_SESSION['a'] = $a; 
         echo "& passwords match."; 
      } else { // username exists, but password is wrong 
         $_SESSION['a'] = $a; 
         echo "& passwords don't match ..."; 
      } 

   } 
} 

?>

Posted: Thu Sep 11, 2003 1:55 pm
by JAM
phice wrote:Where's your session_start(); ?
:D
Just thought of that too, but here

Code: Select all

<?php 
 $_SESSION['a'] = 'foo';
 echo $_SESSION['a'];
?>
...works fine, so I forgot abput that it depends on the php.ini settings. (Uhm... right?)

Posted: Thu Sep 11, 2003 1:55 pm
by zick
IT'S ALWAYS THE STUPID THINGS THAT GET ME OFF
i'm going to try adding the session stuff again and i'll see if that works, thanks for that help ... but what does that original error mean.

Posted: Thu Sep 11, 2003 2:05 pm
by JAM
It means that it expects the $qry to be either:

Code: Select all

$qry = "string";
$qry = $var;
$qry = 1; // a number
...but as you are missing the ", it continues until the next ". So far, so good (even if it's at that point actually broken ;))
It finds the next ", and then wants a ; after that as in my first example here above. But it's not there, so it breaks!

Hence your original post about getting a parse error on a row, thats commented out...

Hope you understood this blurry explanation hehe

Posted: Thu Sep 11, 2003 2:17 pm
by zick
its like those errors in windows:
your computer has commited an illegal operation ... pagefault at 0xf60a1b blah, blah, blah

what does that mean :wink:

now everything works sortof ... here's the new prob. i enter a username and password that i know are in the database.

Code: Select all

$lid = mysql_connect($hst, $usr, $pwd);

$qry = "select * from user where name = '$uid';
$rsl = mysql_query($qry);


if (mysql_num_rows ($rsl) == 0) {
   $_SESSION['a'] = $a; // no users by provided name available
   echo "user doesn't exist ...";
}
and all i get is an echo back of user doesn't exist ... but i think i can figure this ... thaks guys again.

Posted: Thu Sep 11, 2003 2:28 pm
by JAM

Code: Select all

$qry = "select * from user where name = '$uid';
is still wrong

Code: Select all

$qry = "select * from user where name = '$uid'"; // note the "; ending the line here
See my 2nd post on this in this topic...

Posted: Thu Sep 11, 2003 4:55 pm
by Bizwala
What everyone is trying to say zick is...

The error
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/http/public_html/acs/index.php on line 23

Is telling you that it expects a STRING a VAR or a NUMSTRING and it stops at line 23
Therefore, you need to look at line 22 for any missing ",;,' etc...

On line 22 you are missing the " at the end of your query statement. Fixing that will clean up that error. :)

Posted: Thu Sep 11, 2003 7:59 pm
by phice
Exactly what JAM said (I noticed it when I reviewed my post again, and noticed almost everything was red...).