I'm quite new to php although i understand the foundation of php. Most of it atleast.
there are 2 problems with my php script.
One: Even though i typed-in the information inside the text box it always directs me to the ?insert=empty im not sure why it's always telling me that one of the boxes are empty even though it isn't. is it the input type="date"?.
Two: I tried removing the if(empty) method leaving the mysqli query. And it works just fine although no data was inserted into the database.
PHP
session_start();
if (isset($_POST['submit'])) {
include 'includes/dbh.inc.php';
$id = $_GET['id'];
$c_id = $_REQUEST['u_uid'];
$e_name = mysqli_real_escape_string($conn, $_POST['e_name']) ;
$d_event = mysqli_real_escape_string($conn, $_POST['d_event']) ;
$t_event = mysqli_real_escape_string($conn, $_POST['t_event']) ;
$e_t_event = mysqli_real_escape_string($conn, $_POST['e_t_event']) ;
$theme = mysqli_real_escape_string($conn, $_POST['theme']) ;
$date = date('Y-m-d H:i:s');
if (empty($e_name) || empty($d_event) || empty($t_event) || empty($e_t_event) || empty($theme)){
header("Location: ../package.all.php?insert=empty");
exit();
}else{
$sql = "INSERT INTO event_table (event_name, event_date, event_time_start, event_time_end, cusact_id, theme, reserve_date_time, package_id) VALUES ('$e_name', '$d_event', '$t_event', '$e_t_event', '$theme', '$date', '$id');";
mysqli_query($conn, $sql);
header("Location: ../package.all.php?insert=success");
}
}
else {
echo 'isset was false';
header("Location: ../inquire-packages.inc.php?insert=failed");
}
HTML
<form action="includes/inquire-packages.inc.php" method="POST">
<label>Event Name</label>
<input type="text" name="e_name" placeholder="Enter Event Name*"/>
<label for="job">Day of the Event</label>
<input type="date" name="d_event" placeholder="Enter Date of Event*"/>
<label for="job">Time of the Event</label>
<input type="Time" name="t_event" placeholder="Enter Time of Event*"/>
<label for="job">End Time of the Event</label>
<input type="Time" name="e_t_event" placeholder="Enter End Time of Event*"/>
<label>Theme</label>
<input type="text" name="theme" placeholder="Enter Theme*"/>
<input name="submit" type="submit" value="Submit"/>
</form>
I'm sorry if this is a stupid question but i really want to learn php code.
Thank you, Omar