Jump to content

I need A little help with forms.


madpinchr

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>

Archived

This topic is now archived and is closed to further replies.

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