Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3857455 • Letter: W

Question

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.

Please create a user account as the video in course materials to connect mySQL. We should use:

username: iw3htp

password: password

So the connection codes should be something like:

if ( !( $database = mysql_connect( "localhost", "iw3htp", "password" ) ) )
         die( "<p>Could not connect to database</p>" );

Please walk me through the entire process. If there need to be multiple files please let me know.

Explanation / Answer

<?php

if ($_POST['submit']) {

mysql_connect ("localhost", "iw3htp", "password") or die ( "<p>Could not connect to database</p>" );

mysql_select_db("URL") or die ('Data error:' . mysql_error());

$text1 = mysql_real_escape_string($_POST['url']);

$text2 = mysql_real_escape_string($_POST['description']);

$query="INSERT INTO Urltable (url_link,description) VALUES ('$text1','$text2')";

mysql_query($query) or die ('Error updating database' . mysql_error());

}

?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<textarea name="url">URL LINK</textarea>

<textarea name="description">DESCRIPTION</textarea>

<input name="submit" type="submit" value="submit" />

</form>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote