Forum Moderators: coopster

Message Too Old, No Replies

Login And Password Form

mysql query and mysql error

         

AliTaylor4411

7:48 pm on Aug 18, 2010 (gmt 0)

10+ Year Member



I have created a simple form

<form method="post" action= "loginscript.php">
<p><strong><center>USERNAME:</center></strong><br/>
<center><input type= "text" name="username"/></center></p>
<p><strong><center>PASSWORD:</center></strong><br/>
<center><input type = "text" name= "password"/></center></p>
<p><center><input type= "submit" name = "submit" value="login"/></strong></center></p>
</form>
</body>
</html>

which then goes to a script but I keep getting the following messages:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in *(*(*(*(

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in *(*(*(*(*

Obviously my query is incorrect so here it is - can anyone give me a clue as to what is wrong?

$sql = "SELECT firstname, surname FROM agent WHERE
username = '".$_POST["username"]. "'AND
password = PASSWORD('".$_POST["password"]."')";
$result = mysql_query($mysql, $sql) or die(mysql_error($mysql));


Thanks

brotherhood of LAN

8:05 pm on Aug 18, 2010 (gmt 0)

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



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


Try swapping the variables around to look like this

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


[php.net...]

AliTaylor4411

8:11 pm on Aug 18, 2010 (gmt 0)

10+ Year Member



Hi

Thanks for the advice - I have just sorted it by changing from

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

to

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

And it worked!

Matthew1980

8:19 pm on Aug 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there AliTaylor4411,

I recommend that you change your password encrypting method as that & md5 have been cracked, check this out for an alternative: [uk2.php.net ]

And this is when I found out :) [webmasterworld.com ]

Have fun, and yes, the query goes first, then the connection reference, but don't forget that once you have a connection going (from a previous instance) all subsequent query's inherit the last know connection handle - save typing imho.

Cheers,
MRb