Forum Moderators: coopster

Message Too Old, No Replies

I have an issue(err a few)

         

Imdbombboarder

7:10 am on Apr 10, 2006 (gmt 0)

10+ Year Member



Having some problems, first i was trying to make a login, that would allow you to access an upload script. I had it all written out, and then i got a error on the cookie i told it to place. I took that out just to elimate the variables, and then i got another, but this one has me stumpt. I got this error:

Parse error: parse error, unexpected '>' in /home/content/K/e/v/html/userloginscript.php on line 24

Heres the code:

<?php
include ('TopPart.php')
?>

<?php
if ((!$_POST[username]) ¦¦ (!$_POST[password])) {
header("Location: userlogin.htm");
exit;
}

$conn = mysql_connect("sql.example.net", "user", "pass")
or die (mysql_error());
mysql_select_db("mydb", $conn) or die(mysql_error());
$sql = "SELECT username FROM auth_users where username =
'$_POST[username]' and password = password('$_POST[password]')';
$result = mysql_query($sql,$con) or die(mysql_error());

if (mysql_num_rows($result) == 1) {

$username = mysql_result($result, 0, 'username');
$password = mysql_result($result, 0, 'password');

$display_block = "<P>$username have been Authorized!</p>
<p>Your Authorized Abilities:
<ul>
<li><a href=\"fileupload.htm\">Upload Form</a>
</ul>";

} else {

header("Location: userlogin.htm");
exit;
}
?>
<html>
<head>
<title>Upload Form Login</title>
</head>
<body>
<? echo "$msg";?>
</body>
</html

<?php
include ('BottomPart.php')
?>

Any help?

[edited by: jatar_k at 6:10 pm (utc) on April 10, 2006]
[edit reason] removed login details [/edit]

Imdbombboarder

7:11 am on Apr 10, 2006 (gmt 0)

10+ Year Member



Also, i have some spaces, but the line its havin trouble on is the $display block

orion_rus

11:24 am on Apr 10, 2006 (gmt 0)

10+ Year Member



try this: )
$display_block = "<P>".$username." have been Authorized!</p> ............
good day to you)

Imdbombboarder

4:24 pm on Apr 10, 2006 (gmt 0)

10+ Year Member



Ok, but what is the unexpected '>' telling me? I thought it ment i didn't have something with a close carrot, but i dunno. Also, ill post the script, but I also got a parse error saying unexpected T_String....what does that mean?

jatar_k

6:18 pm on Apr 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Imdbombboarder,

your quoting is messed up in this line

$sql = "SELECT username FROM auth_users where username =
'$_POST[username]' and password = password('$_POST[password]')';

what happens is that when you miss a parentheses, brace, a semi colon or mismatch quotes the error shows up later in the code. If you get an error for a specific line and you can't see anything wrong with it then you move up[ from the reported place in the script line by line.

Your line above should read

$sql = "SELECT username FROM auth_users where username = '" . $_POST[username] . "' and password = password('" . $_POST[password] . "')";

your final quote was single instead of double. I also pulled the $_POST vars out and concatenated the string as well. Array variables don't get parsed properly between double quotes so you should use this method.

another tip: I would strictly advise against using $_POST vars directly in your queries sent to mysql. This opens the door for SQL injection and allows for exploitation of your db. You need to clecn those vars first.

try this thread on PHP User Authentication and Passwords [webmasterworld.com] from our library [webmasterworld.com]. There are a few other interesting threads in there as well. ;)

Imdbombboarder

12:08 am on Apr 11, 2006 (gmt 0)

10+ Year Member



<?php
include ('TopPart.php')
?>

<?php
if ((!$_POST[username]) ¦¦ (!$_POST[password])) {
header("Location: userlogin.htm");
exit;
}

$conn = mysql_connect("@@@.@@@", "@@@@", "@@@@@")
or die (mysql_error());
mysql_select_db("EugeneRC", $conn) or die(mysql_error());
$sql = "SELECT username FROM auth_users where username = '" . $_POST[username] . "' and password = password('" . $_POST[password] . "')";
$result = mysql_query($sql,$con) or die(mysql_error());

if (mysql_num_rows($result) == 1) {

$username = mysql_result($result, 0, 'username');
$password = mysql_result($result, 0, 'password');

$display_block = "<P>".$username." have been Authorized!</p>
<p>Your Authorized Abilities:
<ul>
<li><a href=\"fileupload.htm\">Upload Form</a>
</ul>";

} else {

header("Location: userlogin.htm");
exit;
}
?>
<html>
<head>
<title>Upload Form Login</title>
</head>
<body>
<? echo "$msg";?>
</body>
</html

<?php
include ('BottomPart.php')
?>

---------
Now this: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/K/e/v/KevinKelm/html/userloginscript.php on line 15
lol this is hard!

Habtom

6:49 am on Apr 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shouldn't this

$result = mysql_query($sql,$con) or die(mysql_error());

be like this:

$result = mysql_query($sql,$conn) or die(mysql_error());

Your Connection is conn and not con

Habtom

Habtom

6:50 am on Apr 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



. . . and yes

$sql = "SELECT username FROM auth_users where username = '" . $_POST[username] . "' and password = password('" . $_POST[password] . "')";

should go something like:

$sql = "SELECT username FROM auth_users where username = '" . $_POST[username] . "' and password = '" . $_POST[password] . "'";

Habtom

Imdbombboarder

6:47 pm on Apr 11, 2006 (gmt 0)

10+ Year Member



Haha thanks, ill try it. Sorry, still very new to the language!