Question

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

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.]

MY PHP CODE IS GIVING ME PROBLEMS!!!! PLEASE HELP!!!!

Urlinfo.php

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 );
?>

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>

urls.sql

DROP DATABASE IF EXISTS URLs;

CREATE DATABASE URLs;

USE URLs;

CREATE TABLE urltable
(
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
URL varchar(128),
description varchar(255)
);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<html>

<body>

<?php

if(isset($_POST["url"]))

{

mysql_connect("localhost","root","");

mysql_query("CREATE DATABASE `url` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci");

mysql_select_db("url");

mysql_query("

CREATE TABLE IF NOT EXISTS `urltable` (

`url` varchar(1000) NOT NULL,

`descrip` varchar(1000) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1"

);

?>

<?php

mysql_connect("localhost","root","");

mysql_select_db("url");

$url = $_POST["url"];

$url= str_replace("'","&apos;",$url);

$desc = $_POST["des"];

$desc = str_replace("'","&apos;",$desc);

mysql_query("INSERT INTO urltable (url,descrip) VALUES ('$url','$desc')");

?>

<?php

$username="root";

$password="";

$database="url";

mysql_connect("localhost",$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM urltable";

$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();

?>

<table border="1" cellspacing="4" cellpadding="4">

<tr>

<td><font face="Arial, Helvetica, sans-serif">Value1</font></td>

<td><font face="Arial, Helvetica, sans-serif">Value2</font></td>

</tr>

<?php

$i=0;

while ($i < $num) {

$f1=mysql_result($result,$i,"url");

$f2=mysql_result($result,$i,"descrip");

?>

<tr>

<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>

</tr>

<?php

$i++;

}}

else

{

?>

<div>

<form name="subm" action="test.php" method="POST">

<label for="url" style="float: top;">URL:</label><input type="text" name="url" />

<label for="desc"style="float: top;">Description:</label><input type="text" name="des">

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

</form>

</div>

<?php

}

?>

</body>

</html>

Add a comment
Know the answer?
Add Answer to:
Write a PHP script that obtains a URL and its description from user and stores the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need a PHP code that has a box to type in that allows the user to...

    Need a PHP code that has a box to type in that allows the user to put the information through the PHP site to the database for the following categories: INT, First name, Last name, Sex. Once injected it needs to echo to the page to show the table of all entries. The code below is how far I got with it. MySQL: add a row and query $link = mysql_connect('stewcraw.dotstermysql.com', 'prof', '3632password'); if (!$link) { die('Could not connect: '...

  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

  • 1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database....

    1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE permission to the new role for the Orders and OrderItems table. Give SELECT permission for all user tables. 2. Write a script that (1) creates a login ID named “RobertHalliday” with the password “HelloBob”; (2) sets the default database for the login to the MyGuitarShop database; (3) creates a user named “RobertHalliday” for the login; and (4) assigns the user...

  • PHP Programming In this project, you will create a Web page that allows visitors to your...

    PHP Programming In this project, you will create a Web page that allows visitors to your site to sign a guest book that is saved to a database. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element. Add the following text and elements to the document body: <h2>Enter your name to sign our guest book</h2>...

  • 1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database....

    1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE permission to the new role for the Orders and OrderItems table. Give SELECT permission for all user tables. 3) Write a script that uses dynamic SQL and a cursor to loop through each row of the Administrators table and (1) create a login ID for each row in that consists of the administrator�s first and last name with no space...

  • In this assignment you will combine HTML, PHP, and SQL in order to create a web...

    In this assignment you will combine HTML, PHP, and SQL in order to create a web form that allows a manager to add films to the sakila database. You will also create a method to allow the manager to view a list of all films along with their related information, and a list of actors in the movies. Task 1 Create an initial HTML page titled manager.html with 2 buttons. The first button will be labeled “View Films”, and the...

  • Write a PHP program using a ''FOR loop' to compute and print the employee's salary for...

    Write a PHP program using a ''FOR loop' to compute and print the employee's salary for some number of years with a percent increase each year. Your submit button should re-call this page and use PHP to create a table of salaries for each year starting at 1 up to the value of the years variable. So if 'years' is equal to 5, there should be 5 rows in your table. For each year, the salary increases by X%. Make...

  • PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head>...

    PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head> <script> </script> </head> <body> <h2>Temperature Conversion Table</h2> <h4>Enter a starting value in degrees Fahrenheit and an increment value.</h4> <form name="myTemp" onsubmit="convertCelcius()" method="post"> <input type="text" name="temperature"> Enter an value in degrees Fahrenheit<br><br> <input type="radio" name="degIncrement" id="degIncrement5"> Convert in increment in 5 degrees<br> <input type="radio" name="degIncrement" id="degIncrement10"> Convert in increment in 10 degrees <br/><br/><input type="submit" value="Submit"> </form> <?php if( $_POST["temperature"] || $_POST["degincrement"] ) { //get he...

  • CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT...

    CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT INTO DEPT VALUES (10,'SPORTS','NEW YORK'); INSERT INTO DEPT VALUES (20,'HOME','DALLAS'); INSERT INTO DEPT VALUES (30,'OUTDOOR','CHICAGO'); INSERT INTO DEPT VALUES (40,'CLOTHING','BOSTON'); CREATE TABLE EMP ( EMPNO INTEGER NOT NULL, ENAME VARCHAR(10), JOB VARCHAR(9), MGR INTEGER, SAL FLOAT, COMM FLOAT, DEPTNO INTEGER NOT NULL, FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO), FOREIGN KEY (MGR) REFERENCES EMP(EMPNO), PRIMARY KEY (EMPNO)); INSERT INTO EMP VALUES (7839,'KING','PRESIDENT',NULL, 5000,NULL,10); INSERT INTO...

  • Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php...

    Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php script, create an associative array named $order that stores the following values: - the number of cheese toppings; - the number of pepperoni toppings; - the number of ham toppings; - the size of the ordered pizza; - the number of the ordered pizza; - the total cost of the order; - the discount rate; - the total cost after the discount. 2) the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT