Write a PHP script that obtains a URL and its description from user and stores t
ID: 3857276 • Letter: W
Question
Write a PHP script that obtains a URL and its description from user and stores the information into a database using MySQL. Create and run a SQL script with 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. [Note: Follow the instructions in Section 18.5.2 to create the Url database by using the URLs.sql script that's provided with this chapter's examples in the dbscripts folder.]
Explanation / Answer
---------------------------------------------------------------------
USER URL ENTEY FORM
urlentry.html
---------------------------------------------------------------------
<section id="mid_section">
<div id="boxes">
<h1>
Enter your URL name and discription here:
</h1>
<br/>
<form id="myform" action="urlinfo.php" method="post">
URL:<input type="text" value="url">
Description:<input type="text" value="description">
<button id="sub">Submit</button>
</form>
------------------------------------------
Script to connect to database and insert data in Urltable
urlinfo.php
------------------------------------------
<?php
$conn = mysql_connect('<host name>','<datebase user name>','<data base password>');
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
$url =$_POST['url'];
$Description =$_POST['Description'];
if(mysql_query("INSERT INTO Urltable ('URL','URL_DESCRIPTION') VALUES ('".$url."','".$Description."')"))
echo"successfully inserted";
else
echo "failed";
?>
------------------------------------------------
myscript.js
----------------------------------------------
$("#sub").click(function(){
$.post($("#myform").attr("action"), $("#myform:input").serializeArray(), function(info){$("#result").html(info);});
});
$("#myform").submit(function(){
return false;
});
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.