Question

Write a PHP script that obtains a URL and its description from a user and stores...

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 contents of the database in a table

username: iw3htp

password: password

database: URLs

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( "<p>Could not connect to database</p>" );

      if ( !mysqli_select_db( $database, "URLs") )
         die( "<p>Could not open URL database</p>" );

      if ( !( $result = mysqli_query( $database, $query) ) )
      {
         print( "<p>Could not execute query!</p>" );
         die( mysqli_error() );
      }    

     while ( $row = mysqli_fetch_row( $result ) )
               print( "<tr><td>" . $row[ 0 ] . "</td><td>" . $row[ 1 ] . "</td></tr>" );


      mysqli_close( $database );

Homework Answers

Answer #1

If you have any doubts, please give me comment...

<?php

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

die( "<p>Could not connect to database</p>" );

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

die("<p>Could not open URL database</p>");

$query = "SELECT * FROM Urltable";

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

print( "<p>Could not execute query!</p>" );

die(mysqli_error());

}

print("<table border='1px'>");

print("<tr><th>URL</th><th>Description</th></tr>");

while($row = mysqli_fetch_row($result))

print( "<tr><td>".$row[0]."</td><td>".$row[1]."</td></tr>");

print("</table>");

mysqli_close($database);

?>

Know the answer?
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
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT