Page 1 of 1

script submits twice

Posted: Fri Aug 06, 2004 4:32 am
by DaRk
I have a script that lets the user submit his link and then puts it in a file. that file is the read and shown on to the appropiate page. But if press ed submit it submits the previous entry and the entry of the current user. How do I fix it?

Here is the code:

Code: Select all

<?
require_once("links.php");

if ($_POST == "submit") {
	$file = "links.php";
	$name = $HTTP_POST_VARS["name"];
	$url = $HTTP_POST_VARS["url"];

	$fp = fopen ($file, 'a+');
	
	$string = '<a href="'.$url.'/" target="_blank">'.$name.'</a><br>\n';
	
	fwrite ($fp,$string);
	fclose ($fp);
}
?>
<form method="post" action="<?php echo($PHP_SELF); ?>">
Name of your site: <input type="text" name="name">
URL: <input type="text" name="url">
<input type="submit" name="submit" value="sumbit">
</form>
</p>

Posted: Fri Aug 06, 2004 5:00 am
by JayBird
some of your code needs updating and some of it is wrong

Code: Select all

<? 
require_once("links.php"); 

if ($_POST['submit'] == "submit") { 
   $file = "links.php"; 
   $name = $_POST['name']; 
   $url = $_POST['url']; 

   $fp = fopen ($file, 'a+'); 
    
   $string = '<a href="'.$url.'/" target="_blank">'.$name.'</a><br>\n'; 
    
   fwrite ($fp,$string); 
   fclose ($fp); 
} 
?> 
<form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>"> 
Name of your site: <input type="text" name="name"> 
URL: <input type="text" name="url"> 
<input type="submit" name="submit" value="sumbit"> 
</form>