As part of a MySQL driven CMS I need to pass an id to a page which inserts new content into a database table
The links on one page, dealt with using an array, include the query string after .php such as ?id=8 - all good.
The form page needs to use this id in a hidden field: exhibition_id.
So far the form submits the two shown fields, an image file name and an image caption, but the hidden field is coming out as "0"
I'm probably doing something really daft, but right now I'm blind to it.
Here's the code at the top of the page:
and here's the hidden field:
any ideas?
thanks
The links on one page, dealt with using an array, include the query string after .php such as ?id=8 - all good.
The form page needs to use this id in a hidden field: exhibition_id.
So far the form submits the two shown fields, an image file name and an image caption, but the hidden field is coming out as "0"
I'm probably doing something really daft, but right now I'm blind to it.
Here's the code at the top of the page:
Code:
<?php
session_start();
// if session variable not set, redirect to login page
if (!isset($_SESSION['authenticated'])) {
header('Location: ../back_office/index.php');
exit;
}
$exhibition_id = $_GET['id'];
if (array_key_exists('insert', $_POST)) {
include('../db_dual_connect.php');
include('../magic_quotes.php');
// remove backslashes
nukeMagicQuotes();
// prepare an array of expected items
$expected = array('image', 'caption', 'exhibition_id');
// create database connection
$conn = dbConnect('admin');
// make $_POST data safe for insertion into database
foreach ($_POST as $key => $value) {
if (in_array($key, $expected)) {
${$key} = mysql_real_escape_string($value);
}
}
// prepare the SQL query
$sql = "INSERT INTO exhibition_images (image, caption, exhibition_id)
VALUES('$image', '$caption', '$exhibition_id')";
// process the query
$result = mysql_query($sql) or die(mysql_error());
}
?>
and here's the hidden field:
Code:
<input name="exhibition_id" type="hidden" id="hiddenField" value="<?php echo '$exhibition_id' ?>" />
any ideas?
thanks