Jump to content

Undefined variable but how


vipsa

Recommended Posts

Hi 

 

I am a newbie. I get an error undefined variable subject and it is the line in the form where subject is but how can the variable be undefined if I define it in the beginning? Why then is the other variable $text also then not undefined.

 

I also get allot of css code in the form

<?php
if(!isset($_POST['submit'])) {
$from = '[email protected]';
$subject = $_POST['subject'];
$text = $_POST['emailbody'];
$output_form = false;
 
if(empty($subject) && empty($text)) {
  echo 'You forgot the subject and text';
  }
$output_form = true;
if(empty($subject) && !empty($text)) {
  echo 'You forgot to enter the subject';
  }
  $output_form = true;
if(!empty($subject) && empty($text)) {
  echo 'You forgot to enter the text';
  }
  }
  else {
  $output_form = true;
  }
 
  if($output_form) {
    ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <label for="subject">Subject</label><br>
      <input type="text" id="subject" name="subject" value="<?php echo $subject; ?>"><br>
      <label for="emailbody">Email body</label><br>
      <textarea id="emailbody" name="emailbody" rows="5" cols="20" ><?php echo $text; ?></textarea><br>
      <input type="submit" name="submit" value="submit">
    </form>'
<?php
        }
?>
Link to comment
https://forums.phpfreaks.com/topic/283642-undefined-variable-but-how/
Share on other sites

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.