I always keep getting this error when I try to load my site which i need a solution to. tried all i can since am in new to php, i cant seem to solve it.
(" Notice: Undefined index: name in C:\xampp\htdocs\ak\index.php on line 11
Notice: Undefined index: email in C:\xampp\htdocs\ak\index.php on line 12
Notice: Undefined index: website in C:\xampp\htdocs\ak\index.php on line 13
Notice: Undefined index: comment in C:\xampp\htdocs\ak\index.php on line 14 ")
PS: My code is as follows :
[php]
if (isset($_POST[“submit”])){
$con = mysqli_connect (“localhost”, “rupert”, “” , “example”) or die (“Database connect error”);
mysqli_select_db($con, “example”) or die (“error connecting to database”);
$query = “SELECT * FROM validation”;
mysqli_query ($con , $query);
$result = mysqli_query ($con , $query);
$rows = mysqli_fetch_assoc($result);
if (!empty($_POST["name"])){
$query = "INSERT INTO validation (Name, Email, Website, Comment)
VALUES('$name' , '$email' , '$website' , '$comment')";
mysqli_query($con, $query) ;
}
}
//Define variables and set them to empty variables
$namErr = $emailErr = $websiteErr = $commentErr = $genderErr ="";
if($_SERVER[“REQUEST_METHOD”] ==“POST”) {
if(empty($_POST[“name”])){
$namErr = “Name is Required”;
}else{
$name = test_input( $_POST[“name”]);
}
if(empty($_POST[“email”])){
$emailErr = “Email is Required”;
}else{
$email = test_input($_POST[“email”]);
}
if(empty($_POST[“website”])){
$websiteErr = “Website is Required”;
}else{
$website = test_input($_POST[“website”]);
}
if(empty($_POST[“comment”])){
$commentErr = “Comment is Required”;
}else{
$comment = test_input($_POST[“comment”]);
}
if(empty($_POST[“gender”])){
$genderErr = “Gender is Required”;
}else{
$gender = test_input($_POST[“gender”]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
EMAIL : * <?php echo $emailErr ;?>
WEBSITE : * <?php echo $websiteErr ;?>
COMMENT : * <?php echo $websiteErr ;?>
GENDER : Female Male * <?php echo $genderErr ;?>