Forum Moderators: coopster

Message Too Old, No Replies

parse error

cannot fix parse error

         

meau

2:29 am on Sep 1, 2005 (gmt 0)

10+ Year Member



Hello everybody, I have been reading your forum for some guidance in a problem I have with a php script. I am coming up with this error:Parse error: parse error, unexpected T_STRING in /home/(etc etc).php on line 5. Line 5 looks like this:
$rs0_query="mysql_query ("select * from \reciprocal_admin where id=" .
The full section is this:
$rs0_query="mysql_query ("select * from \reciprocal_admin where id=" . $_SESSION["reciproc_adminid"]. " and password ='" . str_replace("'","''",$_POST["password"]) . "'" )";
if ($rs0="mysql_fetch_array($rs0_query)")

If anyone can advise me on what I have done wrong, I would greatly appreciate it.

dlefree

2:50 am on Sep 1, 2005 (gmt 0)

10+ Year Member



Potential issue with:

if ($rs0="mysql_fetch_array($rs0_query)")

Try:

if ($rs0=="mysql_fetch_array($rs0_query)")

dkin

3:14 am on Sep 1, 2005 (gmt 0)

10+ Year Member



Im prolly wrong because I have been awake for 36 hours straight but try changing this

$rs0_query="mysql_query ("select * from \reciprocal_admin where id=" . $_SESSION["reciproc_adminid"]. " and password ='" . str_replace("'","''",$_POST["password"]) . "'" )";

to this

$rs0_query="mysql_query ("select * from \reciprocal_admin where id=" . $_SESSION['reciproc_adminid']. " and password ='" . str_replace("'","''",$_POST['password']) . "'" )";

meau

3:26 am on Sep 1, 2005 (gmt 0)

10+ Year Member



Thank you,
I will try both suggestions and see what happens.

ergophobe

1:14 pm on Sep 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are creating strings when you want to be calling functions. As far as the parser is concerned, there is no difference between

$x = "mysql_query(query stuf)";

$x = "gobbledy gook";

However, once you do this:

$x = "gobbledy gook ("select" . $var);

You have unmatched quotes and parse errors.

$rs0_query= mysql_query ("select * from reciprocal_admin where id=" . $_SESSION["reciproc_adminid"]. " and password ='" . str_replace("'","''",$_POST["password"]) . "'" )";

if ($rs0 = mysql_fetch_array($rs0_query))

I don't understand this though: str_replace("'","''",$_POST["password"])

What are you attempting there?


Try:

if ($rs0=="mysql_fetch_array($rs0_query)")

Actually, don't. mysql_fetch_array() is going to return a resource which is never going to meet the equality comparison. In fact, if the fetch fails and you have error reporting turned down, this should return true without error. When the fetch finds no data, it returns false and an unintialized variable gets treated as 0, an empty string, a boolean false etc. So for a failed fetch, this would be the same as

if (false == false)

which evaluates to TRUE - exactly the opposite of what you want. In this case you actually want to assign the value to $rs0 and evaluate that so that

if ($rs0 = some_data)

is the same as

if (true)

which is what you want.

dlefree

9:57 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



Aaah... I think perhaps dkin and I need to start sleeping more regularly...

dkin

12:51 am on Sep 2, 2005 (gmt 0)

10+ Year Member



nope just need to start paying attention, or perhaps learning lol.