Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- 2 <body>
- 3
- 4 <?php^M
- 5 ^M
- 6 // Connect to the database^M
- 7 //need to change the dbname, user and password^M
- 8
- 9 $dbconn = pg_connect("host= wozniak.eecs.ku.edu port=5432 dbname=jshaw user=jshaw password= mj1l2JLZ") or
- 10 die('Could not connect: ' . pg_last_error());
- 11
- 12 //create a table
- 13 $query = "CREATE TABLE Regi
- 14 (
- 15 UserEmailAddress varchar(50),
- 16 passwd varchar(50),
- 17 privilege varchar(50)
- 18 )";
- 19 $query = pg_query($query); // Execute the Query
- 20
- 21
- 22 //performing update
- 23 $ldata['UserEmailAddress'] = $_POST["username"];
- 24 $ldata['passwd'] = $_POST["password"];
- 25
- 26 //debugging
- 27 echo "<h2> $ldata[UserEmailAddress] : $ldata[passwd] </h2>";
- 28
- 29 $res = pg_insert($dbconn, "Regi", $ldata) or die('Query failed: ' . pg_last_error()); //assuming a table called regiusers
- 30
- 31 if($res)
- 32 {
- 33 echo "<h2> success </h2><br />";
- 34 }
- 35
- 36 // Performing SQL query
- 37 $query = 'SELECT * FROM Regi';
- 38 $result = pg_query($query) or die('Query failed: ' . pg_last_error());
- 39
- 40 // Printing results in HTML
- 41 echo "<table>\n";
- 42 while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
- 43 echo "\t<tr>\n";
- 44 foreach ($line as $col_value) {
- 45 echo "\t\t<td>$col_value</td>\n";
- 46 }
- 47 echo "\t</tr>\n";
- 48 }
- 49 echo "</table>\n";
- 50
- 51 // Free resultset
- 52 pg_free_result($result);
- 53
- 54 // Closing connection
- 55 pg_close($dbconn);
- 56 ?>
- 57
- 58 </body>
- 59 </html>
- 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
- PHP Notice: Undefined index: username in /users/049/j/jshaw/public_html/EECS647/HW4/dbtest.php on line 23
- PHP Notice: Undefined index: password in /users/049/j/jshaw/public_html/EECS647/HW4/dbtest.php on line 24
- <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