Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/263505-i-need-a-little-help-with-forms/
Share on other sites

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

 

<form action="<?=$PHP_SELF?>" method="post">
    <label>Enter one link per line</label>
    <textarea name="links"></textarea>
</form>

<?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:

 

<ul>
<?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)) {
?>
<li><a href="<?=$result["link"]?>" target="_blank"><?=$result["link"]?></a></li>
<?php
}
?>
</ul>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.