FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL: Checking if data is correct?





DjMilez
If I had a form, such as a log in form, how would I get it so it would check the posted data against a table in a database, and if it is found, does something, and if it doesn't find it, does something else?

-DjMilez.
polly-gone
What I do it have the form, then this is what I use to validate:

Code:
<?php
//echo "echo";
   //we don't want mysql injections
    //echo "$_POST[\'username\']";
   $username = $_POST['username'];
    //echo "$username";
    //echo "$_POST['password']";
   $password = $_POST['password'];
    //echo "$password";
   $passwordmd5 = md5($password);
    //echo "$passwordmd5";
    //echo "echo2";

   //Includes
   include ('../includes/config.php');
   include ('../includes/functions.php');

   //Open Connection
   $connection = mysql_connect($host, $user, $pass) or die('Unable to connect to the Atomic Dingo Productions Database');

   //Select 'home' Database
   mysql_select_db($db) or die('Unable to connect to the \'home\' Database');

   //Generate and Execute Query
   $query = "SELECT username, password, userlevel, contact, verif FROM users WHERE username = '$username' AND password = '$passwordmd5'";
   $result = mysql_query($query) or die("Error in query: $query. " . mysql_error());

   //IF Records Present
   if ($row = mysql_fetch_array($result)) {
         setcookie('user', $row['username'],0,'/',".atomicdingo.us");
            // echo $_COOKIE['user'];
         setcookie('level', $row['userlevel'],0,'/',".atomicdingo.us");
             // echo $_COOKIE['level'];
             setcookie('pass', $row['password'],0,'/',".atomicdingo.us");
             // echo $_COOKIE['pass'];
             setcookie('verif', $row['verif'],0,'/',".atomicdingo.us");
             // echo $_COOKIE['verif'];
   
             header('Location: http://atomicdingo.us/index.php?section=client&page=home');
   }else{
      ?>
      <div align="center">
         <font color="#ff0000">INVALID Username or Password!</font>
      </div>
      <?php
   }


What you want to do is check the Data they entered to see if it matches the data in the table.

-Nick Cool Cool Cool
Related topics
Wat vind jij van frihost?
Somebody using my database ?
MySQL database
Resolved- Please lock.
The Host
FTP problems, unable to connect
My post gone
Megaman Phoenix
Number or date/time field for timestamp?
Check the closest event in Calendar?
Login system doesn't work
No password reset details in my email... HELP!
php link
Storing MySQL connection data securely and conveniently
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.