Guest User

Untitled

a guest
Apr 22nd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <html>
  2. 2 <body>
  3. 3
  4. 4 <?php^M
  5. 5 ^M
  6. 6 // Connect to the database^M
  7. 7 //need to change the dbname, user and password^M
  8. 8
  9. 9 $dbconn = pg_connect("host= wozniak.eecs.ku.edu port=5432 dbname=jshaw user=jshaw password= mj1l2JLZ") or
  10. 10 die('Could not connect: ' . pg_last_error());
  11. 11
  12. 12 //create a table
  13. 13 $query = "CREATE TABLE Regi
  14. 14 (
  15. 15 UserEmailAddress varchar(50),
  16. 16 passwd varchar(50),
  17. 17 privilege varchar(50)
  18. 18 )";
  19. 19 $query = pg_query($query); // Execute the Query
  20. 20
  21. 21
  22. 22 //performing update
  23. 23 $ldata['UserEmailAddress'] = $_POST["username"];
  24. 24 $ldata['passwd'] = $_POST["password"];
  25. 25
  26. 26 //debugging
  27. 27 echo "<h2> $ldata[UserEmailAddress] : $ldata[passwd] </h2>";
  28. 28
  29. 29 $res = pg_insert($dbconn, "Regi", $ldata) or die('Query failed: ' . pg_last_error()); //assuming a table called regiusers
  30. 30
  31. 31 if($res)
  32. 32 {
  33. 33 echo "<h2> success </h2><br />";
  34. 34 }
  35. 35
  36. 36 // Performing SQL query
  37. 37 $query = 'SELECT * FROM Regi';
  38. 38 $result = pg_query($query) or die('Query failed: ' . pg_last_error());
  39. 39
  40. 40 // Printing results in HTML
  41. 41 echo "<table>\n";
  42. 42 while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
  43. 43 echo "\t<tr>\n";
  44. 44 foreach ($line as $col_value) {
  45. 45 echo "\t\t<td>$col_value</td>\n";
  46. 46 }
  47. 47 echo "\t</tr>\n";
  48. 48 }
  49. 49 echo "</table>\n";
  50. 50
  51. 51 // Free resultset
  52. 52 pg_free_result($result);
  53. 53
  54. 54 // Closing connection
  55. 55 pg_close($dbconn);
  56. 56 ?>
  57. 57
  58. 58 </body>
  59. 59 </html>
  60.  
  61. PHP Warning: pg_query(): Query failed: ERROR: relation "regi" already exists in /users/049/j/jshaw/public_html/EECS647/HW4/dbtest.php on line 19
  62. PHP Notice: Undefined index: username in /users/049/j/jshaw/public_html/EECS647/HW4/dbtest.php on line 23
  63. PHP Notice: Undefined index: password in /users/049/j/jshaw/public_html/EECS647/HW4/dbtest.php on line 24
  64. <h2> : </h2>PHP Notice: pg_insert(): Failed to query meta_data for 'Regi' table SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotNULL, a.atthasdef, a.attndims FROM pg_class as c, pg_attribute a, pg_type t WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = 'Regi' AND a.atttypid = t.oid ORDER BY a.attnum; in /users/049/j/jshaw/public_html/EECS647/HW4/dbtest.php on line 29
Add Comment
Please, Sign In to add comment