Note: Undefined Variable: Name in C: \ AppServ \ www \ ContactUs.php on line 217
source link: https://www.codesd.com/item/note-undefined-variable-name-in-c-appserv-www-contactus-php-on-line-217.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Note: Undefined Variable: Name in C: \ AppServ \ www \ ContactUs.php on line 217
This question already has an answer here:
- PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” 23 answers
I make contact us form which show error when field empty
The problem is that I try to make it when fill some field and other not, the error show in empty field and filled field still have their data.
& every time I get this error:
Notice: Undefined variable: name in C:\AppServ\www\ContactUs.php on line 217
This is my code:
<?php
if (!empty($_POST['action']) && $_POST['action'] == "send") {
$name = $_POST ['name'];
if (!$name || $name == '') {
$name_error = 'Please insert name';
} else {
$name_error = '';
}
?>
also this
<div title="Send" style="padding: 5px; text-align: left">
<form action="" method="post">
<input type="hidden" name="action" value="send" />
<table style="border: 0px;">
<tr>
<td style="color: white">Full name:<a class="notemptycolor">*</a></td>
<td>
<input type="text" value="<?= $name ?>" name="name"/>
<?= !empty($name_error) ? '<div style="margin-top: 10px; margin-bottom: 10px; color: red;background-color: white" >' . $name_error . '</div>' : '' ?>
</td>
</tr>
</table>
<input type="image" name="submit" src="images/sendBtn.gif" style="float: right; margin-top:9px; margin-right:20px;">
</form>
<?php
$name = "";
if (!empty($_POST['action']) && $_POST['action'] == "send") {
$name = $_POST ['name'];
if (!$name || $name == '') {
$name_error = 'Please insert name';
} else {
$name_error = '';
}
?>
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK