Query String - $_GET problem

stevet70

New Member
Messages
35
Reaction score
0
Points
0
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:
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
 

akkudreamz

New Member
Messages
183
Reaction score
0
Points
0
it should be
Code:
<input name="exhibition_id" type="hidden" id="hiddenField" value="<?php echo $exhibition_id ?>" />
 

VPmase

New Member
Messages
914
Reaction score
1
Points
0
Using <?=$exhibition_id?> is the same as doing <?php echo '$exhibition_id'; ?>
Just a FYI
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Using <?=$exhibition_id?> is the same as doing <?php echo '$exhibition_id'; ?>
Just a FYI

Just be careful to test that short tags are enabled if you move the code to a new host (or the current host upgrades; short tags will be around for awhile but are being replaced with a different syntax).

Short tags also don't play well with XML processing instructions, such as an <?xml?> directive at the start of an XHTML document (which has its own disadvantages in IE). It's not hard to get them to work together, but the extra effort is greater than the advantage of a few saved keystrokes that short tags afford.
 
Top