Richard Korts
asked on
Data from database row not refelected in session variable
I have a MySQL database. When I fetch a specific record with "SELECT * from projects where pid = 40", I get the attached. Note the column bfh1 = "Y". I have a php program that reads the contents of the record & stores the results into a series of $_SESSION variables. That program, with echos added to see what is happening, is here:
The echos produce this:
proj qry= SELECT * from projects where pid = 40
p[bfh1] = Y
bfh1 =
bfh2 = Y
Why is the "Y" value of bfh1 not shown in $_SESSION['bfh1']?
missingbfh1.JPG
<?php
error_reporting(E_ALL);
// load_proj.php
$pid = intval($_GET['ppid']);
$nosumm = intval($_GET['nosumm']);
$ddocs = $_GET['disp_docs'];
//echo "ddocs in load_projn = " . $ddocs . "<br>";
session_start();
include "db_connect_nb.php";
$qry = "SELECT * from projects where pid = " . $pid;
echo "proj qry= " . $qry. "<br>";
$res = mysqli_query($link, $qry);
$p = mysqli_fetch_array($res,MYSQLI_ASSOC);
echo "p[bfh1] = " . $p['bfh1'] . "<br>";
// set all the session stuff
$_SESSION['project'] = $pid . "~" . $p['project_name'];
$_SESSION['cltype'] = $p['cltype'];
$_SESSION['class'] = $p['cltype'];
$_SESSION['wttp'] = $p['wttp'];
$_SESSION['liq_type'] = $p['liq_type'];
$_SESSION['liq_source'] = $p['liq_source'];
$_SESSION['pgrp'] = $p['pgrp'];
$_SESSION['flow'] = $p['flow'];
$_SESSION['flevel'] = $p['flevel'];
$_SESSION['access'] = $p['access'];
$_SESSION['model'] = $p['model'];
$_SESSION['net_price'] = $p['net_price'];
$_SESSION['total_price'] = $p['trade_price'];
$_SESSION['mtype'] = $p['Material'];
$_SESSION['afs'] = $p['AFS'];
$_SESSION['wof'] = $p['wof'];
$_SESSION['atra'] = $p['atra'];
$_SESSION['abf'] = $p['ABF'];
$_SESSION['spapp'] = $p['SP_APP'];
$_SESSION['spabv'] = $_P['SP_ABV'];
$_SESSION['spake'] = $p['SP_AKE'];
$_SESSION['spafs'] = $_P['SP_AFS'];
$_SESSION['gcs'] = $p['gcs'];
$_SESSION['gce'] = $p['gce'];
$_SESSION['fsp'] = $p['fsp'];
$_SESSION['bfh1'] = $p['bhf1'];
$_SESSION['bfh2'] = $p['bfh2'];
$_SESSION['bfh3'] = $p['bfh3'];
$_SESSION['bfh4'] = $p['bfh4'];
$_SESSION['crs1'] = $p['crs1'];
$_SESSION['crs2'] = $p['crs2'];
echo "bfh1 = " . $_SESSION['bfh1'] . "<br>";
echo "bfh2 = " . $_SESSION['bfh2'] . "<br>";
if (!isset($_SESSION['vid'])) {
// insert new record
$qry = "SELECT * from nxtcvid";
$res = mysqli_query($link, $qry);
$nid = mysqli_fetch_array($res,MYSQLI_ASSOC);
$newid = $nid['nxtvid'] + 1;
$qryu = "UPDATE nxtcvid set nxtvid = " . $newid;
$res = mysqli_query($link, $qryu);
$_SESSION['vid'] = $newid;
}
// check for ls250
if ($_GET['fr'] == "ls250") {
// send emil here
require_once('class.phpmailer.php');
// get user info
//echo "session[ruser]" = $_SESSION['ruser'] . "<br>"
$qry = "SELECT * from registered_users where email = '" . $_SESSION['ruser'] . "'";
$res = mysqli_query($link, $qry);
$r = mysqli_fetch_array($res,MYSQLI_ASSOC);
}
//echo "nosumm = " . $nosumm . "<br>";
//echo " ddocs, end of load_projn = " . $ddocs . "<br>";
// ls250_debug
$qryu = "UPDATE ls250_debug set pid_load_proj = " . $pid . ", sess_proj = '" . $_SESSION['project'] . "' where ruid = " . $_SESSION['ruid'] . " and pid = " . $_SESSION['pid'];
//if ($_SESSION['ruid'] == 867) {
//echo "qryu ls250_debug in load_projn = " . $qryu . "<br>";
//}
$resu = mysqli_query($link, $qryu);
header("Location: summary.php?fr=proj&nosumm=" . $nosumm . "&ddocs=" . $ddocs);
exit;
?>
The echos produce this:
proj qry= SELECT * from projects where pid = 40
p[bfh1] = Y
bfh1 =
bfh2 = Y
Why is the "Y" value of bfh1 not shown in $_SESSION['bfh1']?
missingbfh1.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.