I made the create event page, but when I submit the data doesn't go to my database, I tried using the insert feature in PHPMyAdmin and it requires that I enter also the user_id even tho I made a relationship between the 2 tables
I guess I have to retrieve the user_id of the logged-in user , but I couldn't do it I keep getting an error message.
NOTE: this website if for a school assignment!!
<?php
require "config.php";
include("auth.php");
if(isset($_POST['submit'])) {
$event_name=$_POST["event_name"];
$event_description=$_POST["event_description"];
$video_url=$_POST["video_url"];
$image_url=$_POST["image_url"];
$start_date=$_POST["start_date"];
$end_date=$_POST["end_date"];
$start_time=$_POST["start_time"];
$end_time=$_POST["end_time"];
$sql_query="INSERT INTO event_details ( event_name, event_description , video_url, image_url, start_date, end_date, start_time, end_time) values('$event_name','$event_description','$video_url','$image_url','$start_date','$end_date','$start_time','$end_time')";
if(mysqli_query($con,$sql_query)) {
header("Location: adminevents.php");
}
}
?>
that is the code in the form
<?php
// Calling the Connection file!
require "config.php";
session_start();
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
$username = stripslashes($_REQUEST['username']);
$username = mysqli_real_escape_string($con,$username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
//Checking is user existing in the database or not
$query = "SELECT * FROM users WHERE username='$username' and password='$password'";
$result = mysqli_query($con,$query);
$rows = mysqli_num_rows($result);
if($rows==1){
$_SESSION['username'] = $username;
// Redirect user to a welcome page
header("Location: welcome.php");
}
else {
echo "<div class='wrongpass' style='color:red; font-size:12px; margin-left: 3px;'><h3>Username or password is incorrect.</h3> </div> <br/>";
}
} ?>
this is my login code
<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$db_name="sistdb";
$mysql_user="root";
$mysql_pass="";
$server_name="localhost";
$con=mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
if(!$con) {
echo "Connection Error ..." .mysql_connect_error();
} ?>
this is database connection
<?php
session_start();
if(!isset($_SESSION["username"])){
header("Location: login.php");
exit();
} ?>
this is session start code
<?php
require "config.php";
include("auth.php");
$query "SELECT user_id FROM `users` WHERE username = $_SESSION['username']";
$result = mysqli_query($con,$query);
$row=mysqli_fetch_assoc($result)
$userid = $row["user_id"];
if(isset($_POST['submit'])) {
$event_name=$_POST["event_name"];
$event_description=$_POST["event_description"];
$video_url=$_POST["video_url"];
$image_url=$_POST["image_url"];
$start_date=$_POST["start_date"];
$end_date=$_POST["end_date"];
$start_time=$_POST["start_time"];
$end_time=$_POST["end_time"];
$sql_query="INSERT INTO event_details ( event_name, event_description , video_url, image_url, start_date, end_date, start_time, end_time) values('$event_name','$event_description','$video_url','$image_url','$start_date','$end_date','$start_time','$end_time')";
if(mysqli_query($con,$sql_query)) {
header("Location: adminevents.php");
}
}
?>
if I try to retrieve user_id from SQL by username stored in session I get
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp64\www\assignment\addevent.php on line 5
line 5 is where have $query = SELECT