Omar Mandeeli Omar Mandeeli - 3 months ago 22
HTML Question

Data not inserting when I include $_SESSION and $_GET

I don't know know what seems to be a problem here. I tried to include a $_SESSION and $_GET and inserting into a variable. The query works fine it seems to be executing it properly but no data inserted into the database.

$_SESSION and $_GET has a data. I tried echoing it and it displays the data that I wanted which is stored from the database.



include_once 'packages-header.php';

include 'includes/';

mysqli_select_db($conn, "test");
$sql = "SELECT * FROM package";
$data = mysqli_query($conn, $sql);

while ($record = mysqli_fetch_array($data)) {

$id = $record['package_id'];

echo "<table border = 1>";
echo "<tr>";
echo "<th>" . $record['package_name'] . "</th>";

echo "</tr>";
echo "<tr>";
echo "<td>" . "<br />" . $record['package_details'] . "<br />" . "</td>" ;

echo "<tr/>";

echo "<td><a href='package.all.php?id=$id'>Submit</a></td>";


echo "</table>";

if (isset($_POST['submit'])) {

$p_id = $_GET['id'];
$c_id = $_SESSION['u_id'];
$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)){


$sql = "INSERT INTO event_table (event_name, event_date, event_time_start, event_time_end, cusact_id, theme, reserve_date_time) VALUES ('$e_name', '$d_event', '$t_event', '$e_t_event', '$c_id', '$theme', '$date');";
mysqli_query($conn, $sql);

else {

echo 'isset was false';




if (isset($_SESSION['u_uid'])) {

echo '<form action="includes/" method="POST">
<button type="submit" name="submit">logout</button>

} else {
echo '<form action="Login.php"><button type="submit" name="submit">
Login</button> </form>
<form action="signup.php"> <button type="submit" name="signup">Signup</button> </form>';
<span class='follow'>
<a class='links' href='#' target='_blank' title='Twitter'>
<i class='fa fa-twitter'></i>

<a class='links' href='#' target='_blank' title='Youtube'>
<i class='fa fa-facebook'></i>
<a class='links' href='#' target='_blank' title='Youtube'>
<i class='fa fa-google-plus'></i>



<div class="form-style-5">

<form 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*"/>

<input type="text" name="theme" placeholder="Enter Theme*"/>
<input name="submit" type="submit" value="Submit"/>

<footer id='contacts'>

<span class='cc'>
@ 2014 . Zaldy Ducusin
<script src="" type="text/javascript"></script>
window.jQuery || document.write('<script src="/javascripts/libs/jquery-1.10.2.min.js"><\/script>')
<script src="javascripts/libs/holder.js" type="text/javascript"></script>
<script src="javascripts/plugins.js" type="text/javascript"></script>
<script src="javascripts/formsjs.js" type="text/javascript"></script>


I'm quite new to PHP so please bear with me. Still learning. Thank you so much for your time :)

Answer Source

Try this and it will give you error message.:

$sql = "INSERT INTO event_table (event_name, event_date, event_time_start, event_time_end, cusact_id, theme, reserve_date_time) VALUES ('$e_name', '$d_event', '$t_event', '$e_t_event', '$c_id', '$theme', '$date');";
$result = mysqli_query($conn, $sql);

        echo("Error description: " . mysqli_error($conn));

Read more: