PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/createAccount.php

https://bitbucket.org/wlynch92/cs336-dbproject
PHP | 86 lines | 70 code | 15 blank | 1 comment | 10 complexity | 45d0794b339cbb3a5441c071110a420b MD5 | raw file
  1. <html>
  2. <head>
  3. <title>Account Creation</title>
  4. </head>
  5. <body>
  6. <a href="/"><h1>Music Box</h1></a>
  7. A social music site for everyone!
  8. <p><center><hr width=100% noshade=noshade></center>
  9. <h2> Account Creation </h2>
  10. <i> * = required field</i><p>
  11. <form action="createAccount.php" method="POST">
  12. <b>Basic information</b><br>
  13. First name: <input type="textbox" name="fname"><br/>
  14. Last name: <input type="textbox" name="lname"><br/>
  15. Username: <input type="textbox" name="username">*<br/>
  16. Birthdate: <input type="date" name="bdate">*<br/>
  17. Email: <input type="textbox" name="email"><br/>
  18. Address: <input type="textbox" name="address"> <i>e.g. 99 Davidson Rd. Piscataway, NJ, USA</i><br/>
  19. Gender: <select name="gender">
  20. <option value="Male">Male</option>
  21. <option value="Female">Female</option>
  22. </select>*<br/>
  23. Profile Picture URL: <input type="textbox" name="purl"><br/>
  24. <input type="submit" value="next >>">
  25. </form>
  26. </body>
  27. </html>
  28. <?php
  29. session_start();
  30. function setval($post) {
  31. if ($post){
  32. return "'".$post."'";
  33. } else {
  34. return "NULL";
  35. }
  36. }
  37. if ($_POST['username'] && $_POST['gender'] && $_POST['bdate']){
  38. $con = mysql_connect("cs336-64.rutgers.edu", "csuser", "cs277315");
  39. if (!$con) {
  40. die('cannot connect: '.mysql_error());
  41. }
  42. mysql_select_db("cs336",$con);
  43. $query = "SELECT MAX(uid) as max FROM user";
  44. $res = mysql_query($query,$con);
  45. if (!$res){
  46. die(mysql_error());
  47. }
  48. $row=mysql_fetch_array($res);
  49. $newuid=$row['max']+1;
  50. /* global for next page */
  51. $_SESSION['newuid'] = $newuid;
  52. $fname=setval($_POST['fname']);
  53. $lname=setval($_POST['lname']);
  54. $username=setval($_POST['username']);
  55. $bdate=setval($_POST['bdate']);
  56. $email=setval($_POST['email']);
  57. $address=setval($_POST['address']);
  58. $gender=setval($_POST['gender']);
  59. $purl=setval($_POST['purl']);
  60. $query = "INSERT INTO user VALUES ($newuid,$gender,$address,$username,$fname,$lname,$email,$bdate,$purl)";
  61. $res = mysql_query($query,$con);
  62. if (!$res){
  63. echo "Error in creating account\n<br/>\n";
  64. mysql_close($con);
  65. } else {
  66. mysql_close($con);
  67. header("Location: /addEdu.php");
  68. exit;
  69. }
  70. }
  71. ?>