Page 1 of 1

[SOLVED] define $variable as a form field

Posted: Sun Nov 23, 2003 8:50 pm
by dull1554
i'm working on a script to process a form and write it to a flat file, but when i go to submit the form it tells me i have undefined variables, i thought as long as i used the php script as the action it would allready have the variables defined.

Posted: Sun Nov 23, 2003 8:58 pm
by d3ad1ysp0rk
can you show us your script?

Posted: Sun Nov 23, 2003 9:01 pm
by dull1554
yep hang on

Posted: Sun Nov 23, 2003 9:05 pm
by dull1554
I have 4 files

add_dl.php
add_dl.html
download.txt
downloas.php


they are as follows.....


add_dl.php

Code: Select all

<?php

if($submit) &#123;
if($name == "")
  $message = "Please input a name";
else if($link == "")
  $message = "Please input a link";
else if($info == "")
  $message = "Please describe the download";

if($message)
  echo($message);
else &#123;
$fp = fopen("download.txt", "w+");
$insertcode = "<table><tr><td width='200' border='1'>$name - <a href='$link'>download</a></td></tr><tr><td width='200' border='1'>$info</td></tr></table>";
fwrite($fp, $insertcode);
fclose($fp);
  &#125;
&#125;
?>
add_dl.html

Code: Select all

<html>
<head>
<title>
</title>
</head>
<body>
<form action='add_dl.php' method='post'>
Name of download: <input type='text' name='name'>
<br>
Link: <input type='text' name='link'>
<br>
Information: <br> <textarea name="info" rows='5' cols='30' wrap="soft">Enter your download description here.</textarea>
<input type='submit' value='submit'>
</body>
<!--(C) Dull1554 -->
</html>
download.txt is a empty file...

downloas.php

Code: Select all

<html>
<head>
<title>
</title>
</head>
<body>
<h3>Downloads</h3>
<p>
<?php include "download.txt" ?> 
</body>
<!--(C) Dull1554 -->
</html>

Posted: Sun Nov 23, 2003 9:11 pm
by d3ad1ysp0rk
you never ended your form on 'add_dl.html'

</form> add that after the submit button

Posted: Sun Nov 23, 2003 9:16 pm
by dull1554
that still does not solve my problem, i still get this:

Notice: Undefined variable: name in c:\program files\apache group\apache\htdocs\downloads\add_dl.php on line 4

Notice: Undefined variable: name in c:\program files\apache group\apache\htdocs\downloads\add_dl.php on line 15

Notice: Undefined variable: link in c:\program files\apache group\apache\htdocs\downloads\add_dl.php on line 15

Notice: Undefined variable: info in c:\program files\apache group\apache\htdocs\downloads\add_dl.php on line 15

Posted: Sun Nov 23, 2003 9:16 pm
by infolock
my eyes went straight to add_dl.php, and kinda just stayed there.

you have some wierd calls and so i'm assuming it's giving you that the errors are coming from it.

try this instead :

Code: Select all

<?php 

if((!isset($_POST['name']) or (!isset($_POST['link']) or (!isset($_POST['info']))
{
     echo 'You must enter <b>ALL</b> fields before you can continue!';
     exit;
}
$name = $_POST['name'];
$link = $_POST['link'];
$info = $_POST['info'];


$fp = fopen("download.txt", "w+"); 
$insertcode = "<table><tr><td width='200' border='1'>".$name." - <a href='".$link."'>download</a></td></tr><tr><td width='200' border='1'>".$info."</td></tr></table>"; 
fwrite($fp, $insertcode); 
fclose($fp); 
  } 
} 
?>

reply

Posted: Sun Nov 23, 2003 9:22 pm
by dull1554
thanks infolock you had a error but i fixed it and it works exactly how i want it to, thanks a bunch

Code: Select all

<?php

if((!isset($_POST&#1111;'name'])) or (!isset($_POST&#1111;'link'])) or (!isset($_POST&#1111;'info'])))
&#123;
     echo 'You must enter <b>ALL</b> fields before you can continue!';
     exit;
&#125;
$name = $_POST&#1111;'name'];
$link = $_POST&#1111;'link'];
$info = $_POST&#1111;'info'];


$fp = fopen("download.txt", "w+");
$insertcode = "<table><tr><td width='200' border='1'>".$name." - <a href='".$link."'>download</a></td></tr><tr><td width='200' border='1'>".$info."</td></tr></table>";
fwrite($fp, $insertcode);
fclose($fp);
  &#125;<--not needed
&#125;<--not needed
?>

Posted: Sun Nov 23, 2003 9:28 pm
by infolock
oops, missed those :) glad it worked though.