When the data from the following form is submitted to action.php
, it prints the second variable date
of the form but gives an error for the first and third field. Why is that ?
HTML:
<form method="post" action="./action.php">
<span id="type_tweet">Type your tweet</span>
<span>
<textarea rows="4" cols="80" id="tweet_entered"> </textarea>
</span>
<hr />
<span>When to tweet</span>
<span id="date"> <!-- Date -->
<input type="text" name="SelectedDate" id="SelectedDate" readonly onClick="GetDate(this);">
</span>
<span id="at">@</span>
<span id="time"> <!-- Time-->
<input type="text" class="timepicker" name="SelectedTime" id="timepicker" />
</span>
<span>
<input type="submit" value="submit" id="schedule_button" />
</span>
</form>
PHP: (action.php)
<?php
echo $_POST["tweet_entered"];
echo "<br />";
echo $_POST["SelectedDate"];
echo "<br />";
echo $_POST["timepicker"];
echo "<br />";
?>
Errors when action.php
is run :
Notice: Undefined index: tweet_entered in E:\Installed_Apps\xampp\htdocs\twibuffer\action.php on line 2
4/29/2014
Notice: Undefined index: timepicker in E:\Installed_Apps\xampp\htdocs\twibuffer\action.php on line 6
You need to change this
<textarea rows="4" cols="80" id="tweet_entered"> </textarea>
to
<textarea rows="4" cols="80" id="tweet_entered" name="tweet_entered"> </textarea>
and
<input type="text" class="timepicker" name="SelectedTime" id="timepicker" />
to
<input type="text" class="timepicker" name="timepicker" id="timepicker" />
The name attribute is what gets loaded into the $_POST variable