I have a table (news
) with different column names. With my code, a new row with these can be added to the database with a text post, which is then echoed in my website.
However, just recently, it stopped working and I noticed that every column name would get updated normally except the one which defines what user has made said post (idUSERS
). It has just stopped working recently, and the website outputs no error when I run the code. I use $_SESSION["idUSERS"]
to get the current logged in user's ID
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "intranet";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: Please try again later" . $conn->connect_error);
}
//$fecha = date("d-m-y");
$fecha = $_POST['news_date'];
$sql = "INSERT INTO news (title, description, date ,tipo, idUSERS)
VALUES ('".$_POST['txtTitle']."', '".$_POST['txtNews']."', '".$fecha."', '".$_POST['cboTipo']."', '".$_SESSION["idUSERS"]."')";
$result = $conn->query($sql);
$conn->close();
header("Location: DelkoINT_home.php");
?>
Database ref. image: https://i.stack.imgur.com/D4y94.png
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "intranet";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "Select * from login_info where loginUsername ='".$_POST['username']."' and loginPassword ='".$_POST['password']."'";
$result = $conn->query($sql);
if ($result ->num_rows >0) {
$row= $result->fetch_assoc();
$_SESSION["idLOGIN"]= $row["idLOGIN"];
$_SESSION["idUSERS"]= $row["idUSERS"];
$_SESSION["admin"]= $row["user_type"];
$_SESSION["surname"]= $row["userSurname"];
header("Location: intranet/DelkoINT_home.php");
}
else {
echo "<font color='red'>The username or password is incorrect!</font><br/ >
<a href = 'Delko_login.php'>Click here to go back</font></a>";
}
$conn->close();
?>
Session data var_dump
on the MySQL writing page:
array(4) {
["idLOGIN"]=> string(1) "2"
["idUSERS"]=> NULL
["admin"]=> string(1) "1"
["surname"]=> NULL
}