hey guys i am a newbie in php therefore i need you help. as the title says i am trying to store variable value into database table.
this is my php code that i wrote however it doesn't seem to be working. it doesn't seem to be storing any values in the database.
<?php
// to connect to database
require("user_connection.php");
$query = "INSERT INTO booked (date, computer_id, name, start_time, end_time) VALUES ('$date', '$select3', '$username', '$select1', '$select2')";
mysqli_query($query);
?>
can you please help me check if there is anything wrong with my code. the database table is called "booked" and the columns are "date, computer_id, name, start_time, end_time". below is the full code of the page
<?php
// starts a session and checks if the user is logged in
error_reporting(E_ALL & ~E_NOTICE);
session_start();
if (isset($_SESSION['id'])) {
$userId = $_SESSION['id'];
$username = $_SESSION['username'];
} else {
header('Location: index.php');
die();
}
?>
<!DOCTYPE html>
<html>
<body>
<!-- heading -->
<div id="intro">Thankyou for booking a slot using the booking system.</div>
<!-- echo out information -->
<div id="fonts">
<h4>Below is the information of your booking:</h4>
</br>
</br>
<b>Student Name:</b> <?php echo $username; // echo's name ?>
</br>
</br>
<b>Room No:</b> <?php $room = $_SESSION['g'];
echo $room; // echo's room ?>
</br>
</br>
<b>Computer No:</b> <?php
$select3 = $_POST['bike'];
echo $select3;
?>
</br>
</br>
<b>Date:</b> <?php $date = $_POST['datepicker'];
echo $date; // echo's date
?>
</br>
</br>
<b>Start Session and End Session:</b> <?php
if(isset($_POST['select1']) && isset($_POST['select2'])) {
$select1 = $_POST['select1'];
$select2 = $_POST['select2'];
echo $select1;
echo "";
echo $select2;
}
else{
echo "not set";
}
?>
</div>
<?php
// to connect to database
require("user_connection.php");
$query = "INSERT INTO booked (date, computer_id, name, start_time, end_time) VALUES ('$date', '$select3', '$username', '$select1', '$select2')";
mysqli_query($query);
?>
</body>
<footer>
<p>Copyright © 2016 MyComputer | Contact information: <a href="mailto:gurungmadan@hotmail.com">gurungmadan@hotmail.com</a></p>
</footer>
</html>