При каждой перезагрузке страницы пишет такое:
Notice: Undefined variable: result in ndex.php on line 151
И так для каждого <input>
.
Я новичок в PHP. Можете сказать, где я ошибся?
Вот код PHP:
<?php
session_start();
if(isset($_POST['send'])){
if(isset($_POST['carlist'])){
$carlist=$_POST['carlist'];
switch($carlist){
case 'jaguar':break;
case 'bmw':break;
case 'mercedes':break;
default:echo "No Choosen any car";
}
}
$name=htmlspecialchars($_POST['name']);
$date=htmlspecialchars($_POST['date']);
$email=htmlspecialchars($_POST['email']);
$_SESSION['name']=$name;
$_SESSION['dtae']=$date;
$_SESSION['email']=$email;
$eror_name="";
$eror_date="";
$eror_email="";
$eror=false;
if(strlen($name) == 0){
$eror_name="Please Chek";
$eror= true;
}
if($email == "" || !preg_match ("/@/",$email)){
$eror_email="Please Chek";
$eror= true;
}
if(empty($date)){
$eror_date="Please Chek";
$eror= true;
}
if(!$eror){
$to="[email protected]";
$subject="Message";
$letter = "Car-Name " . $_POST['carlist'] . "r\n";
$letter .= "Name" . $_POST['name'] . "r\n";
$letter .= "Date" . $_POST['date'] . "r\n";
$letter .= "Email " . $_POST['email']."r\n";
mail($to,$subject,$letter);
$result='<span style="color:red;">Message have been sent</span>';
}
else{
echo $result;
}
}
?>
Вот и код HTML:
<span style="color:red; font-size:20px;"><?php echo $result;?></span>
<form class="form1" action="#" method="post">
<select name="carlist">
<option name="carname"value="Jaguar">JAGUAR</option>
<option name="carname"value="BMW">BMW</option>
<option name="carname"value="MERCEDES">MERCEDES</option>
</select>
<input type="text" id="text" name="name" placeholder="Name" value="<?php $_SESSION['name'];?> " required ><?php echo $eror_name;?>
<input type="date" id="text" name="date" placeholder="Date" value="<?php $_SESSION['date'];?> " required ><?php echo $eror_date;?>
<input type="email" id="text" name="email" placeholder="Email" value="<?php $_SESSION['email'];?> " required ><?php echo $eror_email;?>
<button type="submit" id="carschoose" name="send">ORDER</button>
</form>