Forum Moderators: coopster

Message Too Old, No Replies

PHP Errors

         

cricket

12:47 am on Nov 19, 2004 (gmt 0)

10+ Year Member



Hi,

Please help!

I'm trying to work through the examples in Luke Welling and Laura Thomson's text, "PHP and MySQL Web Development," though with some minor modifications like additional form variables. Yet I can't get them to work, notably the following 2:

1) For one application, I get the following error message:

parse error, unexpected T_CONSTANT_ENCAPSED_STRING

for this line:

$result = mysql_query("INSERT INTO user VALUES ('$username', '$password', '$first', '$last', '$email')");

(If you have the book, it refers to listing 24.9 on pg. 487).

I have also tried it where instead of
$password,
it's
password('$password'),

2) For the other application, I get this error message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

for the following code:

...

$query = 'select * from user '
."where name='$username' "
." and pass=password('$password')";
$result = mysql_query($query, $db_conn);
echo $result;

if (mysql_fetch_array($result) >0 )
{
// if they are in the database register the user id
$HTTP_SESSION_VARS['valid_user'] = $username;
}
}

(FYI, This is on page 226, Listing 10.2 of the same text).

Thank you!

virileone

1:34 am on Nov 19, 2004 (gmt 0)

10+ Year Member



Hey... keep in mind the "parse error on line 20" could mean the error is actually on line 19. So make sure thats not the case...

I use this for insert
$bleh = mysql_query("insert into users(tbl1,tbl2,tbl3) values('$val1','$val2','$val3')");

try using users(foo,bar,etc)

hope thathelps.

dreamcatcher

2:10 am on Nov 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With your SQL error, use mysql_num_rows to see if any rows have been fetched.

$query = mysql_query('select * from user WHERE name='$username' AND pass=password('$password')') or die(mysql_error());

if (mysql_num_rows($query)>0)
{

//blah blah

}

dc

[edited by: dreamcatcher at 2:13 am (utc) on Nov. 19, 2004]

coopster

2:11 am on Nov 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, cricket.

Yes, it seems you may have a syntax error higher up in your code than that statement as it looks good from here.

As far as the second message, are you sure you have a connection established to your database?

cricket

5:24 am on Nov 19, 2004 (gmt 0)

10+ Year Member



Thank you all for the helpful replies! You are right on both.

The error for the 1st application (the one with the parse error message) was indeed higher up. I didn't state a variable correctly. Now I can move on to the rest of the website!

For the 2nd application, I'm working on getting the database connection.

Again, thanks for everything!