/addEdu.php

https://bitbucket.org/wlynch92/cs336-dbproject · PHP · 80 lines · 76 code · 4 blank · 0 comment · 2 complexity · 43c527e66b9f2cafc0ab70244607a38b 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. <?php
  10. session_start();
  11. $con = mysql_connect("cs336-64.rutgers.edu", "csuser", "cs277315");
  12. if (!$con) {
  13. die ('cannot connect: '.mysql_error());
  14. }
  15. mysql_select_db("cs336", $con);
  16. $schoollist = mysql_query("SELECT * FROM school");
  17. ?>
  18. <h2>Account Creation (con't)</h2>
  19. <i>* = required field</i><p>
  20. <form action="addEdu.php" method="POST">
  21. <b>Education</b><br>
  22. School: <select name="school">
  23. <?php
  24. while ($school = mysql_fetch_array($schoollist)) {
  25. echo "<option value=\"".$school['sname']."\">".$school['sname']."</option>";
  26. }
  27. ?>
  28. </select>*<br>
  29. Start date: <input type="date" name="sdate"><br>
  30. End date: <input type="date" name="edate"><br>
  31. Degree: <input type="textbox" name="degree">*<p>
  32. <input type="submit" value="create account!">
  33. </form>
  34. </body>
  35. </html>
  36. <?php
  37. function setval($post) {
  38. if($post) {
  39. return "'".$post."'";
  40. }
  41. else {
  42. return "NULL";
  43. }
  44. }
  45. if ($_POST['school'] && $_POST['degree']) {
  46. $uid = $_SESSION['newuid'];
  47. $sname = setval($_POST['school']);
  48. $srow = mysql_fetch_array(mysql_query("SELECT sid FROM school WHERE sname=$sname"));
  49. $sid = $srow['sid'];
  50. $sdate = setval($_POST['sdate']);
  51. $edate = setval($_POST['edate']);
  52. $degree = setval($_POST['degree']);
  53. $query = "INSERT INTO attended VALUES ($uid, $sid, $sdate, $edate, $degree)";
  54. $res = mysql_query($query, $con);
  55. if (!$res) {
  56. echo "Error in adding education information, please try again!\n<br>\n";
  57. mysql_close($con);
  58. }
  59. else {
  60. echo "Success! Redirecting back to home page.\n<br>\n";
  61. mysql_close($con);
  62. header("Refresh: 2; URL=/");
  63. exit;
  64. }
  65. }
  66. ?>