my script below won’t pull the hashed userid/session to insert into the adminid spot…any advice?
I know it is connecting and setting a hashed session because I can print that out…
thx
[php]<?php
session_start();
echo session_id();
// connect to the database
include(“connect.php”);
{
// if the form’s submit button is clicked, we need to process the form
if (isset($_POST[‘submit’]))
{
//get userid and assign to adminid
$query = ‘SELECT userid
FROM admins
WHERE userid = ?’;
$stmt = $mysqli->prepare($query);
if (!$stmt) {
echo ‘failed to prepare user admin statement’;
} else {
$stmt->bind_param(‘i’, $_POST[‘session_id’]);
$stmt->execute();
echo '
user id is: ';
echo ‘userid’;
}
// get the form data
$foodid = htmlentities($_POST[‘foodid’], ENT_QUOTES);
$restid = htmlentities($_POST[‘restid’], ENT_QUOTES);
$regionid = htmlentities($_POST[‘regionid’], ENT_QUOTES);
$adminid = htmlentities($_POST[‘adminid’], ENT_QUOTES);
// check that foodname and adminid are both not empty
if ($foodname == ‘’ || $adminid == ‘’)
{
// if they are empty, show an error message and display the form
$error = ‘ERROR: Please fill in all required fields!’;
//renderForm($foodname, $adminid, $error);
echo “error–not everything required is filled in…especially foodname and adminid”;
}
else
{
// insert the new record into the database
if ($stmt = $mysqli->prepare(“INSERT food (foodid, restid, regionid, adminid)
VALUES (?,?,?,?)”))
{
$stmt->bind_param(“iiii”, $foodid, $restid, $regionid, $adminid);
$stmt->execute();
$stmt->close();
}
// show an error if the query has an error
else
{
echo "ERROR: Could not prepare SQL statement.";
}
// redirect the user
header("Location: foodform.php");
}
}
// if the form hasn't been submitted yet...
else
{
echo "success";
}
}
// close the mysqli connection
mysqli_close($mysqli);
?>
[/php]