I am trying to use sessions to store information to be able to access on other pages with PHP.
I have done this several times with MySQL and it works perfectly, however with PostGreSQL it doesn't seem to work anywhere other than on the page created.
Here is a very simple example I tried to make and this doesn't even work (if you swap the psql for mysql - the below code works):
index.php:
<?php
include_once("connection.php");
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Index</title>
</head>
<body>
<div class="container">
<p>hello</p>
<form method="post" action="">
<input type="text" name="name">
<input type="submit" name="submit" value="Submit">
</form>
</div>
</body>
</html>
test.php:
<?php
include_once("connection.php");
$username = $_SESSION['name'];
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Index</title>
</head>
<body>
<div class="container">
<?php echo '<p> Hello ' . $username .'</p>';
?>
</div>
</body>
</html>
Connection.php:
<?php
$conn_data = ("host=cimteaching1 port=27005 dbname='enter name' user='enter username' password='enter password'");
$dbconn = pg_connect($conn_data) or die("Cannot connect to db" . pg_last_error());
if(isset($_POST['submit'])) {
$name = $_POST['name'];
session_start();
$_SESSION['name'] = $name;
header("Location: test.php");
}
?>