Sinisterly
Doubt in this script - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: PHP (https://sinister.ly/Forum-PHP)
+--- Thread: Doubt in this script (/Thread-Doubt-in-this-script)

Pages: 1 2


Doubt in this script - Psycho_Coder - 05-05-2013

Will someone help me with this 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.



Doubt in this script - Psycho_Coder - 05-05-2013

Will someone help me with this 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.



RE: Doubt in this script - Coder-san - 05-05-2013

It seems you have to write a PHP script to:-
1) Perform a MySQL query to create a database and table
2) Take user inputs (a) URL (b) description, store in the table, and show the contents of the database in a table format.

Should not be that tough for you.


RE: Doubt in this script - Coder-san - 05-05-2013

It seems you have to write a PHP script to:-
1) Perform a MySQL query to create a database and table
2) Take user inputs (a) URL (b) description, store in the table, and show the contents of the database in a table format.

Should not be that tough for you.


RE: Doubt in this script - Psycho_Coder - 05-05-2013

(05-05-2013, 10:02 AM)Coder-san Wrote: It seems you have to write a PHP script to:-
1) Perform a MySQL query to create a database and table
2) Take user inputs (a) URL (b) description, store in the table, and show the contents of the database in a table format.

Should not be that tough for you.

To be true I don't have good php knowledge. I know only the very basics of php. But I have some work related to this question and I need this to be solved. So I thought if someone can do that for me here on HC. I know it can be said here that "do your own homework and we cannot spoon-feed you ?" , that would be correct as if I get problem then I must ask for references and help but I must not ask directly that solve my question.

Still if someone can solve this question for me I will be grateful.

Thank You,
Sincerely,
Psycho_Coder.


RE: Doubt in this script - Psycho_Coder - 05-05-2013

(05-05-2013, 10:02 AM)Coder-san Wrote: It seems you have to write a PHP script to:-
1) Perform a MySQL query to create a database and table
2) Take user inputs (a) URL (b) description, store in the table, and show the contents of the database in a table format.

Should not be that tough for you.

To be true I don't have good php knowledge. I know only the very basics of php. But I have some work related to this question and I need this to be solved. So I thought if someone can do that for me here on HC. I know it can be said here that "do your own homework and we cannot spoon-feed you ?" , that would be correct as if I get problem then I must ask for references and help but I must not ask directly that solve my question.

Still if someone can solve this question for me I will be grateful.

Thank You,
Sincerely,
Psycho_Coder.


RE: Doubt in this script - Coder-san - 05-05-2013

I don't do much PHP myself.

Lets take an example from W3Schools:-

PHP Code:
<?php $con = mysql_connect("localhost","mysql_user","mysql_pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } $sql = "CREATE DATABASE my_db"; if (mysql_query($sql,$con)) { echo "Database my_db created"; } else { echo "Error creating database: " . mysql_error(); } ?>

First you establish a connection. Then you just perform a query.
The above example is for creating a database. Modify it a little bit for creating table, and so on.
I believe you are ok with SQL queries.


RE: Doubt in this script - Coder-san - 05-05-2013

I don't do much PHP myself.

Lets take an example from W3Schools:-

PHP Code:
<?php $con = mysql_connect("localhost","mysql_user","mysql_pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } $sql = "CREATE DATABASE my_db"; if (mysql_query($sql,$con)) { echo "Database my_db created"; } else { echo "Error creating database: " . mysql_error(); } ?>

First you establish a connection. Then you just perform a query.
The above example is for creating a database. Modify it a little bit for creating table, and so on.
I believe you are ok with SQL queries.


RE: Doubt in this script - hackarchives - 05-05-2013

Create database and tables
PHP Code:
<?php mysql_connect("HOST_NAME","USERNAME","PASSWORD"); 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" ); ?>

Adding values is simple.After creating database and tables simply use a mysql query to add

PHP Code:
mysql_connect("HOST_NAME","USERNAME","PASSWORD"); ); mysql_select_db("url"); $url = "URL GIVEN BY USER"; $url= str_replace("'","&apos;",$url); $desc = "DESCRIPTION"; $desc = str_replace("'","&apos;",$desc); mysql_query("INSERT INTO urltable (url,descrip) VALUES ('$url','$desc')"); ?>

I have replaced ' by &apos; to prevent mysql error in case user has an apostrophe in description or url


RE: Doubt in this script - hackarchives - 05-05-2013

Create database and tables
PHP Code:
<?php mysql_connect("HOST_NAME","USERNAME","PASSWORD"); 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" ); ?>

Adding values is simple.After creating database and tables simply use a mysql query to add

PHP Code:
mysql_connect("HOST_NAME","USERNAME","PASSWORD"); ); mysql_select_db("url"); $url = "URL GIVEN BY USER"; $url= str_replace("'","&apos;",$url); $desc = "DESCRIPTION"; $desc = str_replace("'","&apos;",$desc); mysql_query("INSERT INTO urltable (url,descrip) VALUES ('$url','$desc')"); ?>

I have replaced ' by &apos; to prevent mysql error in case user has an apostrophe in description or url