Question

Submit all php pages you create, as well as the html pages that are rendered as...

Submit all php pages you create, as well as the html pages that are rendered as a result of your actions.

This assignment uses information from multiple previous assignments, so please refer back to those assignments for login information, tutorials etc.

a) (5 point) Create a php page to display the result of the query

SELECT * FROM pg_tables

from your database schema.

Adapt the following example for this purpose:

http://wiki.cs.ndsu.nodak.edu/doku.php?id=classes:general:dbsamples:php_postgres

To avoid having your password in the file, please read the host, dbname, user, and password information from a file not in the public_html directory or its subdirectories.

Leave out the semicolon at the end of SQL statements. It is added automatically.

Notice that by default, the script will only return the 0th column of the output.

b) (5 points) Create a php page to read the name of a school. Add input validation as you see appropriate (you will not be graded on this).

c) (5 points) Upon submission: Print out the complete row for a school in the High_School table from assignment 2, based on the name that was entered.

Link Contents:

PHP example for Postgres database connection

<head>
</head>
<body>

<?php
        // Make a connection to the database
        // The values here MUST BE CHANGED to match the database and credentials you wish to use
        $dbhost = pg_connect("host=hostname dbname=databasename user=username password=password");

        // If the $dbhost variable is not defined, there was an error
        if(!$dbhost)
        {
                die("Error: ".pg_last_error());
        }

        // Define the SQL query to run (replace these values as well)
        $sql = "SELECT * FROM Schema.Tablename";

        // Run the SQL query
        $result = pg_query($dbhost, $sql);

        // If the $result variable is not defined, there was an error in the query
        if (!$result)
        {
                die("Error in query: ".pg_last_error());
        }

        // Iterate through each row of the result 
        while ($row = pg_fetch_array($result))
        {
                // Write HTML to the page, replace this with whatever you wish to do with the data
                echo $row[0]."<br/>\n";
        }


        // Free the result from memory
        pg_free_result($result);

        // Close the database connection
        pg_close($dbhost);
?>

</body>
</html>
0 0
Add a comment Improve this question Transcribed image text
Answer #1
  1. Create HTML view page to get input as school name
  2. Use <input> tag inside form
  3. Assign value for action attribute of the form as resultant PHP
  4. Create another PHP file with database connectivity
  5. Get input school name and check school name is available in database or not
  6. If school name is not found throws an 404 error page
  7. Otherwise create table using HTML table tag in PHP
  8. Return response as webpage
Add a comment
Know the answer?
Add Answer to:
Submit all php pages you create, as well as the html pages that are rendered as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT