PageRenderTime 36ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

https://bitbucket.org/wlynch92/cs336-dbproject
PHP | 60 lines | 52 code | 8 blank | 0 comment | 8 complexity | 5e27476bd9dee20f3376aff01fb8990f MD5 | raw file
  1. <html>
  2. <head><title>Music Box: A social music site for everyone!</title></head>
  3. <body>
  4. <h1><a href="/">Music Box</a></h1>
  5. A social music site for everyone!<p>
  6. <center><hr width=100% noshade=noshade></center><p>
  7. Please log in below:<br/>
  8. <form action="/" method="post">
  9. Username: <input type="text" name="username">
  10. <!--Password: <input type="password" name="password"> -->
  11. <input type="submit" value="Log In">
  12. </form>
  13. <p>
  14. <i>Not a registered user? <a href="/createAccount.php">Create an account</a> now!</i>
  15. <p>
  16. <?php
  17. include('header.php');
  18. session_start();
  19. if ($_SESSION['username']){
  20. header('Location: /profile.php');
  21. exit;
  22. }
  23. if($_POST['username']){
  24. $con = mysql_connect("cs336-64.rutgers.edu", "csuser", "cs277315");
  25. if (!$con) {
  26. die('cannot connect: '.mysql_error());
  27. }
  28. mysql_select_db("cs336", $con);
  29. $user = $_POST['username'];
  30. $result = mysql_query("SELECT * FROM user u WHERE u.username='$user'");
  31. if (mysql_num_rows($result) == 0) {
  32. echo "Error: user not found, please try again.";
  33. }
  34. else {
  35. $row = mysql_fetch_array($result);
  36. $_SESSION['username'] = $row['username'];
  37. $_SESSION['firstname'] = $row['firstname'];
  38. $_SESSION['lastname'] = $row['lastname'];
  39. $_SESSION['uid'] = $row['uid'];
  40. $_SESSION['email'] = $row['email'];
  41. $_SESSION['birth'] = $row['birth'];
  42. $_SESSION['address'] = $row['address'];
  43. $_SESSION['gender'] = $row['gender'];
  44. $_SESSION['picurl'] = $row['picurl'];
  45. header("Location: /profile.php");
  46. exit;
  47. }
  48. mysql_close($con);
  49. }
  50. ?>
  51. </body>
  52. </html>