Advertisement
Guest User

My Attempt

a guest
Jul 31st, 2012
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Test Php Page</title>
  6. </head>
  7.  
  8. <form action="welcome.php" method="post">
  9. User: <input type="text" name="user" />
  10. Password: <input type="password" name="password" />
  11. <input type="submit" />
  12. </form>
  13. </form>
  14.  
  15. </body>
  16. </html>
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. Welcome.php
  24.  
  25. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  26. <html xmlns="http://www.w3.org/1999/xhtml">
  27. <head>
  28. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  29. <title></title>
  30. </head>
  31. <?php
  32. $con = mysql_connect("localhost","root","0000");
  33. if (!$con)
  34. {
  35.     die('Count not connect: ' . mysql_error());
  36. } else
  37. {
  38.     mysql_select_db("phptest", $con);
  39.     $sql = "CREATE TABLE IF NOT EXISTS users
  40.     (
  41.     personID int NOT NULL AUTO_INCREMENT,
  42.    PRIMARY KEY(personID),
  43.     Username varchar(15),
  44.     Password varchar(15)
  45.     )";
  46.    
  47.     mysql_query($sql,$con);
  48.     $user = $_POST["user"];
  49.     $pass = $_POST["password"];
  50.    
  51.     $sql2 = "SELECT * FROM users
  52.     WHERE Username='$user'
  53.     ";
  54.     $result = mysql_query($sql2,$con);
  55.     if($result === FALSE) {
  56.         die(mysql_error());
  57.     } else
  58.     {
  59.     if(mysql_fetch_array($sql2) === FALSE) {
  60.         die(mysql_error());
  61.     } else
  62.     $row = mysql_fetch_array($sql2);
  63.     if ($row['Password'][0] == $pass)
  64.     {
  65.         echo "You Have Logged in correctly";
  66.     } else
  67.     {
  68.         echo "User and Password do not match";
  69.     }
  70.     }
  71.        
  72. }
  73. ?>
  74. <body>
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement