Chicken Posted July 19, 2007 Share Posted July 19, 2007 Is it possible to have a form and to take a url submitted from the form and place it on another page page as a link? Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted July 19, 2007 Share Posted July 19, 2007 is the page html or dynamic Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted July 19, 2007 Share Posted July 19, 2007 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>"; ?> Quote Link to comment Share on other sites More sharing options...
Chicken Posted July 19, 2007 Author Share Posted July 19, 2007 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... Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted July 19, 2007 Share Posted July 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
Chicken Posted July 19, 2007 Author Share Posted July 19, 2007 i was thinking of something using fopen, fwrite, then fclose but i can't seem to get it to work Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 19, 2007 Share Posted July 19, 2007 ... care to post some of the code that isn't quite working? Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted July 19, 2007 Share Posted July 19, 2007 Could do that with an include file that has nothing put links in it. Quote Link to comment Share on other sites More sharing options...
dbillings Posted July 20, 2007 Share Posted July 20, 2007 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 />"; } } ?> Quote Link to comment Share on other sites More sharing options...
Chicken Posted July 20, 2007 Author Share Posted July 20, 2007 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? Quote Link to comment Share on other sites More sharing options...
dbillings Posted July 20, 2007 Share Posted July 20, 2007 If by middle you mean end yes i.e. if you submit <a href="#">TEST</a> Then submit <a href="#">TEST1</a> You will have <a href="#">TEST</a> <a href="#">TEST1</a> Quote Link to comment Share on other sites More sharing options...
Chicken Posted July 20, 2007 Author Share Posted July 20, 2007 When you say end do you mean after </html>? Quote Link to comment Share on other sites More sharing options...
dbillings Posted July 29, 2007 Share Posted July 29, 2007 It doesn't write to an html file it writes to a text file. You can return the result anywhere on the web-page you want it to. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.