我正嘗試使用html和php創建表單,並且我收到了這些錯誤消息。一切都在一個PHP文件。我可以找到任何與我的代碼有關的錯誤。php - 注意:表單上的未定義索引
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 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代碼,我得到的錯誤: -
//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!";
}
有什麼不對?
看到'<形式方法= 「POST」>'建議你用你的整個代碼在同一個頁面; HTML和PHP。錯誤/通知在這裏很明顯。當'