Jump to content


Photo

mysql query and checking if its successful


  • Please log in to reply
4 replies to this topic

#1 Kaisuo

Kaisuo
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 December 2003 - 07:32 PM

[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?

#2 Raichu

Raichu
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 December 2003 - 12:57 AM

No, I reccomend something like this:

<?phpmysql_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
Hey! I thought I would try this out :)

#3 Kaisuo

Kaisuo
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 December 2003 - 02:17 AM

WOW thats chinese! very complicated!

#4 gizmola

gizmola
  • Administrators
  • Advanced Member
  • 4,667 posts
  • LocationLos Angeles, CA USA

Posted 27 December 2003 - 07:57 AM

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).

#5 Kaisuo

Kaisuo
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 December 2003 - 08:12 AM

its just me, I\'m not too familar with:
COUNT(*) AS number
Is there any tutorial or references on mysql_query as in stuff like
SELECT
COUNT
FROM
WHERE
.... Stuff like that?

Could be really useful for me.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users