I have two php files.
addbasket.php
<?php
session_start();
$link = $_SESSION['link'];
if (isset($_SESSION['userid'])) {......}
?>
and
index.php
<?php
session_start();
$_SESSION['link'] = mysqli_connect("localhost","test","test","dbname");
$link = $_SESSION['link'];
....
?>
The file addbasket.php is called by Ajax and given Parameters for article (number) and amount (number)
but the mysqli_query doesnt work. It seems like the $_SESSION['link']
is not there in addbasket.php. It can't be the Session, because the $_SESSION['userid']
is there, right and can be echoed.
What could be the Problem here?
$_SESSION
can only store serializable data.
mysqli_connect
returns a resource. Resources are not serializable.
You'll have to instantiate that DB connection in every request.
Edit: OK, now I understand your actual problem. What you need is some form of this:
db.php
$link = mysqli_connect("localhost","test","test","dbname");
index.php
require 'db.php';
$r = mysqli_query($link, 'SOME QUERY...');
....
addbasket.php
require 'db.php';
$r = mysqli_query($link, 'SOME OTHER QUERY...');
....
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments