Need direction - forms/database issue

I need a little direction. This is my goal:

  1. Create a large text box that allows someone to insert links, one per line, in plain text ( ex. http://www.website.com/image.jpg
  2. Save the data to a unique list saved on the server
  3. Use the list to display thumbnails of all the links on a page that can be clicked to load the actual image.
  4. Create a unique link so that a user can access the list they just made at a later time.

How should I go about starting this project? I have been learning some JavaScript for 3 weeks or so, but it seems that this will not work for my project? A little help? Can this be accomplished with php? What are my best options. I could really use some help. Thank you.

Someone replied to this with the following code and I am confused. My server has php and mysql set up. I have made a fresh database. I am not familar with php or MySQL yet. Does all this code just go into an html file? I could use some info/help please. Note: It would be awesome if any user could access and use this form freely. So I don’t have to worry about extra accounts or permissions.

[code]***
*PHP + MySQL.
*
*You’ll need a table called “links”, e.g.
*


CREATE TABLE links (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
uri VARCHAR(255) NOT NULL
);


*Then you’ll need some PHP


Enter one link per line <?php if (isset($_POST["links"])) { $dbh = mysql_connect("localhost", "username", "password"); mysql_select_db("dbname"); $links = $_POST["links"]; $links = explode("\n", $links); foreach ($links as $link) { $link = mysql_real_escape_string($link); $sql = "INSERT INTO links (uri) VALUES('{$link}')"; mysql_query($sql, $dbh); } } ?>

*And finally, you’ll need a page to display your links:


    <?php $dbh = mysql_connect("localhost", "username", "password"); mysql_select_db("dbname");

    $sql = “SELECT * FROM links”;
    $result = mysql_query($sql, $dbh) or die(mysql_error());

    while ($row = mysql_fetch_assoc($result)) {
    ?>

  • " target="_blank"><?=$result["link"]?>
  • <?php } ?>
[/code]

Hi,

the person who replied to you put ‘working parts’ of code all together in one quote.

This is SQL, so you need to tell this to the database:

CREATE TABLE links (    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,    uri VARCHAR(255) NOT NULL);

This is the part you need to put in a .php file. It shows a form and contains the code to work with the result from the form:
[php]

Enter one link per line <?php if (isset($_POST["links"])) { $dbh = mysql_connect("localhost", "username", "password"); mysql_select_db("dbname"); $links = $_POST["links"]; $links = explode("\n", $links); foreach ($links as $link) { $link = mysql_real_escape_string($link); $sql = "INSERT INTO links (uri) VALUES('{$link}')"; mysql_query($sql, $dbh); } } ?>

[/php]

The last part is the page that displays all the links:
[php]

    <?php $dbh = mysql_connect("localhost", "username", "password"); mysql_select_db("dbname"); $sql = "SELECT * FROM links"; $result = mysql_query($sql, $dbh) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { ?>
  • " target="_blank"><?=$result["link"]?>
  • <?php } ?>
[/php]

I hope this makes things clearer for you. :wink:
Good luck.

O.

Sponsor our Newsletter | Privacy Policy | Terms of Service