Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Write a PHP script that obtains a URL and its description from a user and stores the information into a database using MySQL. Create and

Write a PHP script that obtains a URL and its description from a user and stores the information into a database using MySQL. Create and run a SQL script with a database named URL and a table named Urltable. The first field of the table should contain an actual URL, and the second, which is named Description, should contain a description of the URL. Use www.deitel.com as the first URL, and input Cool site! as its description. The second URL should be www.php.net, and the description should be The official PHP site. After each new URL is submitted, print the con- tents of the database in a table. [Note: Follow the instructions in Section 18.5.2 to create the Url database by using the URLs.sql script thats provided with this chapters examples in the dbscripts folder.]

Submit all files and also have a word document which contains screen shots of working webpages ( include queries and results) from localhost or your ip address. The scripts of database for this chapter are attached here. Please create a user account as the video in course materials to connect mySQL.

We should use:

username: iw3htp

password: password

Starting PHP 7, mysql_connect is no longer used. It is replaced by mysqli. In our homework, the conversion from mysql to mysqli is straightforward.

if ( !( $database = mysqli_connect( "localhost", "iw3htp", "password" ) ) )

die( "Could not connect to database" );

if ( !mysqli_select_db( $database, "URLs") )

die( "Could not open URL database" );

if ( !( $result = mysqli_query( $database, $query) ) )

{

print( "Could not execute query!" );

die( mysqli_error() ); }

while ( $row = mysqli_fetch_row( $result ) )

print( "" . $row[ 0 ] . "" . $row[ 1 ] . "" );

mysqli_close( $database );

18.5.2 Creating Databases in MySQL

For each MySQL database we use in Chapter 19, we provide a SQL script in a .sql file that sets up the database and its tables. You can execute these scripts in the MySQL monitor. In this chapters examples directory, youll find the following scripts:

books.sqlcreates the books database discussed in Section 18.3

products.sqlcreates the Products database used in Section 19.9

mailinglist.sqlcreates the MailingList database used in Section 19.11

URLs.sqlcreates the URL database used in Exercise 19.9.

Executing a SQL Script To execute a SQL script:

1. Start the MySQL monitor using the username and password you created in Section 18.5.1.

In Mac OS X, open a Terminal window and execute the command

/Applications/XAMPP/xamppfiles/bin/mysql -h localhost -u iw3htp -p

The -p option prompts you for the password for the iw3htp user account. When prompted, enter the password password.

2. Execute the script with the source command. For example: source books.sql; creates the books database.

3. Repeat Step 2 for each SQL script now, so the databases are ready for use in Chapter 19.

4. Type the command exit; to terminate the MySQL monitor.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions