This question already has an answer here:
I'm trying to create a form using html and php and I get these error messages. Everything are in one php file. I can find anything that is wrong with my code.
Notice: Undefined index: number in C:\xampp\htdocs\sms\textmessage.php on line 41
Notice: Undefined index: sender in C:\xampp\htdocs\sms\textmessage.php on line 42
Notice: Undefined index: message in C:\xampp\htdocs\sms\textmessage.php on line 43
Notice: Undefined index: send in C:\xampp\htdocs\sms\textmessage.php on line 51
Form code:-
<form method="POST">
<div class="form-group">
<label for="number">Receiver's Number</label>
<input type="tel" name="number" class="form-control" placeholder="Mobile Number" value="<?php echo $number; ?>" />
</div>
<div class="form-group">
<label for="sender">Sender</label>
<input type="text" name="sender" class="form-control" placeholder="Sender's Name" value="<?php echo $from; ?>">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" placeholder="Enter your message here" value="<?php echo $message; ?>"></textarea>
</div>
<input type="submit" class="btn btn-success btn-lg" id="submitbtn" value="Send" name="send"/>
<input type="hidden" name="submitted" value="true">
</form>
php code where I get the error:-
//Get form data
$number = $_POST['number']; //Line 41
$from = $_POST['sender']; //Line 42
$message = $_POST['message']; //Line 43
$message = urlencode($message); //Test that the message is encoded correctly. Php will use urlencode the message
if ($_POST['send']) //Line 51
{
//Validating if the fields are empty
if ($number)
{
$error.="<br />Please enter the receiver's number!";
}
if ($from)
{
$error.="<br />Please enter the Sender's name!";
}
if ($message)
{
$error.="<br />Please enter the text message you want to send!";
}
Is anything wrong?
</div>