Jump to content

mysql query and checking if its successful


Kaisuo

Recommended Posts

[php:1:1d5cc4ec0c]<?php

checkuser($user,$pass) {

$conn = mysql_connect($conn_host, $conn_user, $conn_pass) or die(mysql_error());

$checked = mysql_query(\"SELECT * FROM katima_members WHERE username = \'$user\' AND password = \'$pass\'\");

if($checked) {

$checking == \"ok\";

} else {

$checking == \"error\";

}

mysql_close($conn)

return $checking;

}

?>[/php:1:1d5cc4ec0c]

 

Would this return \"ok\" if the user is in the database and the username and password are correct?

Link to comment
Share on other sites

No, I reccomend something like this:

 


<?php



mysql_connect("localhost", "user", "pass");

mysql_select_db(name of database);

$verify = mysql_query("SELECT COUNT(*) AS number FROM member WHERE user=\'{$HTTP_POST_VARS[\'user\']}\' AND pass=\'{$HTTP_POST_VARS[\'pass\']}\'");



$result = mysql_fetch_array($verify);



if( $result[\'number\'] < 1)

{

echo " Incorrect username or password";

exit();

}





?>

Log in complete! 

 

Just edit the user pass and database name also edit the values for the name in your form

Link to comment
Share on other sites

WOW thats chinese! very complicated!

 

Not really... and it is the best way to handle your problem ;) My only quibble is that you should use $_POST rather than the $HTTP_POST...

 

 

Your code btw, is completely incorrect, because all you are checking is whether your query completed or not. It would almost certainly always be true (assuming you didn\'t have a syntax error in your statement).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.