oooo Verizon LTE 09:33 Expert Q&A; Done Write a PHP script that obtains a URL an
ID: 3857491 • Letter: O
Question
oooo Verizon LTE 09:33 Expert Q&A; Done Write a PHP script that obtains a URL and its description from a user and stores the information into a database using MySOL. Create and run a SOL 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("Could not connect to database"); Please walk me through the entire process. If there need to be multiple files please let me knowExplanation / Answer
PHP Script:
<?php
$con=mysqli_connect("localhost","test","test","test");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to mysqli: " . mysqli_connect_error();
}
else
{
if(isset($_POST['url']) && isset($_POST['desc']))
{
$url=$_POST['url'];
$desc=$_POST['desc'];
$sql= "INSERT INTO urldesc ".
"(`url`,`desc`) ".
"VALUES ('".$url."', '".$desc."')";
mysqli_query($con, $sql);
//mysqli_query($con,"INSERT INTO urldesc (url, desc) VALUES ('". $_POST['url'] ."', '". $_POST['desc'] ."')");
}
}
?>
<html>
<body>
<form action="mypage.php" method='post'>
<input type="text" name='url' />
<input type="text" name='desc' />
<input type="submit" />
</form>
<table border=1>
<th>URL</th>
<th>Description</th>
<?php
$values=mysqli_query($con,"select * from urldesc");
if(! $values )
{
die('Could not get data: ' . mysqli_error());
}
while($row = mysqli_fetch_array($values))
{
echo "<tr><td width='200px'><center>".$row['url']."</center></td><td width='600px'><center>".$row['desc']."</center></td></tr>";
}
mysqli_close($con);
?>
</table>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.