Jump to content

Automaticly Create a Link From a Submit Form?


Chicken

Recommended Posts

FORM.HTML

<form action="pagewithlinks.php" method="post">
    <input type="text" name="newlink"></input>
    <input type="submit" value="Subscribe"></input>
</form>

 

PAGEWITHLINKS.PHP

<?php
$link = $_POST['newlink'];
echo "<a href='$link'>LINK TO WHATEVER YOU TYPED IN</a>";
?>

Link to comment
Share on other sites

FORM.HTML

<form action="pagewithlinks.php" method="post">
    <input type="text" name="newlink"></input>
    <input type="submit" value="Subscribe"></input>
</form>

 

PAGEWITHLINKS.PHP

<?php
$link = $_POST['newlink'];
echo "<a href='$link'>LINK TO WHATEVER YOU TYPED IN</a>";
?>

 

It overwrites the one before it...

Link to comment
Share on other sites

You didn't ask for the links to be added to a database, but it sounds like you will need to write a php program that adds links to a database, then when the pagewithlinks.php page is viewed you will query the database and echo the result of the query. This is about as simple of a task as you can do with php/mysql. I recommend reading this book to learn how to do this:

 

PHP & MySQL For Dummies 3rd edition

Link to comment
Share on other sites

Here you go. No mysql database using fwrite. happy trails.

 



<?php

if(isset($_REQUEST['submit'])){

$filename="links.txt";

$somecontent="****$_REQUEST['links']****";

$handle = fopen("$filename", "ab");

   if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
   }

   echo $somecontent." has been written to ".$filename;
   fclose($handle);
}

?>

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Links</label><input type='text' name='links'><br />
<input type='submit' name='submit' value='Submit'><br />
</form>



Here's the code to retrieve the data and display it.

<?php

$filename="links.txt";


if(file_exists($filename) && filesize($filename) > 0){

$fh = fopen($filename, 'rb');
$thedata = fread($fh, filesize($filename));
fclose($fh);
$break=explode("****",$thedata);

foreach($break as $value){

echo $value."<br />";

}


}
?>

Link to comment
Share on other sites

Here you go. No mysql database using fwrite. happy trails.

 



<?php

if(isset($_REQUEST['submit'])){

$filename="links.txt";

$somecontent="****$_REQUEST['links']****";

$handle = fopen("$filename", "ab");

   if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
   }

   echo $somecontent." has been written to ".$filename;
   fclose($handle);
}

?>

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Links</label><input type='text' name='links'><br />
<input type='submit' name='submit' value='Submit'><br />
</form>



Here's the code to retrieve the data and display it.

<?php

$filename="links.txt";


if(file_exists($filename) && filesize($filename) > 0){

$fh = fopen($filename, 'rb');
$thedata = fread($fh, filesize($filename));
fclose($fh);
$break=explode("****",$thedata);

foreach($break as $value){

echo $value."<br />";

}


}
?>

 

Will it write to the middle of a file without overwriting previous data?

Link to comment
Share on other sites

  • 2 weeks later...
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.