Code help

Support, Snippets & Projects

Moderators: Moderator, Global Moderator

Post Reply
Wayne
Sr. Member
Sr. Member
Posts: 362
Joined: Thu Jun 17, 2004 12:37 am

Code help

Post by Wayne »

[code]  // if ok, put in db
$result = $conn->query(
"insert into user values
(\'$username\', sha1(\'$password\'), \'$email\')");
 if (!$result)
{
   echo \'Could not register you in database - please try again later.\';
}
 return true;
}

function login($username, $password)
// check username and password with db
// if yes, return true
// else throw exception
{
 // connect to db
 $conn = db_connect();

 // check if username is unique
 $result = $conn->query("select * from user
where username=\'$username\'
and passwd = sha1(\'$password\')");
 if (!$result)
    echo "Could not log you in.";

 if ($result->num_rows>0)
    return true;
 else
    echo "Could not log you in.";
}[/code]


This is the first part of a code I\'m having problems with
its line 24 and 42-44 which is this:
[code]
$result = $conn->query(
"insert_into_user_values
(\'$username\', sha1(\'$password\'), \'$email\')");[/code]

and

[code]  $result = $conn->query("select * from user
where username=\'$username\'
and passwd = sha1(\'$password\')");[/code]

I really don\'t know enough PHP to beable to fix this. I\'m sure it can\'t be anything that drastic, but I don\'t know much to be able to fix it. The exact error I\'m getting is this:
Parse error: parse error, unexpected T_STRING in /home/httpd/vhosts/tkdfc.hopto.org/httpdocs/user_auth_fns.php on line 24

Please help!
Thanks
Josh
Hero Member
Hero Member
Posts: 4627
Joined: Fri Jun 04, 2004 2:54 pm

Code help

Post by Josh »

Maybe change those 2 codes to this?:

[code]$result = $conn->query("insert_into_user_values(\'$username\', sha1(\'$password\'), \'$email\')");[/code]

and

[code]$result = $conn->query("select * from user where  username=\'$username\' and passwd = sha1(\'$password\')");[/code]
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Wayne
Sr. Member
Sr. Member
Posts: 362
Joined: Thu Jun 17, 2004 12:37 am

Code help

Post by Wayne »

nope... don\'t work :\'(
Post Reply

Return to “PHP & MySQL”