Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse error T_IF..Newbie Alert

Status
Not open for further replies.

LyallJ

MIS
Jul 18, 2001
124
0
0
US
%-) EXTREME NEWBIE ALERT %-)

This is the error i get:

Parse error: parse error, unexpected T_IF in /var/ on line 16

I have done alot of VB in the past. So i figured i would try some php and get into the web stuff. But, i have ran into a problem. I searched on the internet and all i could find was that i was using a reserved word (if). I have looked high and low. I am using this code from a book, then i can pick it apart and figure out what it is doing. I know thats kinda cheating, but hey, it works for me!!

Heres my Code:

<?
$username = &quot;cust&quot;;
$hostnmae = &quot;localhost&quot;;
$theconnection = mysql_connect($hostname, $username);
print &quot;connected to mysql<br>&quot;;
$mydatabase=mysql_select_db(&quot;milligans&quot;,$theconnection);
$result_ar=mysql_fetch_array(mysql_query(&quot;select count (*) as numfound from username where user='{$HTTP_POST_VARS['user']}' and pass='{$http_POST_VARS['pass']}'&quot;)
if ($result_ar['numfound'] = 0) {
print &quot;login failed unknown user&quot;;
}
else {
print &quot;login succeded&quot;;
}
?>

Thanks for the help!![wavey3]
 
Almost forgot, $username= &quot;cust&quot;; is line 10
 
One problem I know PHP will have with your code is that PHP does not like associative array references inside strings.

For example, PHP does not like:

$a = &quot;Three: $the_array['three']&quot;;

but the equivalent that does work is:

$a = &quot;Three: &quot; . $the_array['three'];

(explicit concatenation of two strings)



Also, the brackets in your mysql_query() invocation line are likely to give PHP fits.



Also, this line:

if ($result_ar['numfound'] = 0) {

is going to give you problems. Unlike VB, PHP differentiates between the assignment operator &quot;=&quot; and the logical comparison operators &quot;==&quot; and &quot;===&quot;. This particular if-clause will always evaluate to FALSE because an assignment operation itself returns a value -- the value assigned. You're assigning the array element the value of zero here.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
And the reason you are getting a parse error is because you are missing the terminating semi-colon on the
Code:
mysql_query
line.

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top