+ Reply to Thread
Results 1 to 6 of 6

Thread: Query String - $_GET problem

  1. #1
    x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    Query String - $_GET problem

    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

  2. #2
    x10 Sophmore akkudreamz is an unknown quantity at this point akkudreamz's Avatar
    Join Date
    Jan 2009
    Location
    Jaipur, Rajasthan, India
    Posts
    183

    Re: Query String - $_GET problem

    it should be
    Code:
    <input name="exhibition_id" type="hidden" id="hiddenField" value="<?php echo $exhibition_id ?>" />
    Be safety conscious. 80% of people are caused by accidents.
    My Weblog

  3. #3
    x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    Re: Query String - $_GET problem

    thanks, perfect!

    obviously time I took a break

  4. #4
    x10 Sophmore akkudreamz is an unknown quantity at this point akkudreamz's Avatar
    Join Date
    Jan 2009
    Location
    Jaipur, Rajasthan, India
    Posts
    183

    Re: Query String - $_GET problem

    Quote Originally Posted by stevet70 View Post
    thanks, perfect!

    obviously time I took a break
    yeah happens to everyone once in a while
    take a break from all this coding stuff.grab a beer and watch a movie
    Be safety conscious. 80% of people are caused by accidents.
    My Weblog

  5. #5
    x10 Elder VPmase is an unknown quantity at this point VPmase's Avatar
    Join Date
    Nov 2007
    Location
    Davenport, IA, USA
    Posts
    899

    Re: Query String - $_GET problem

    Using <?=$exhibition_id?> is the same as doing <?php echo '$exhibition_id'; ?>
    Just a FYI
    Visit my site!
    Always use the search function before posting a new thread!
    Extra10

    Helpful suggestions: Read the rules on every forum, follow said rules, and if you are unsure or need help, search first

  6. #6
    Community Advocate misson is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    1,130

    Re: Query String - $_GET problem

    Quote Originally Posted by VPmase View Post
    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.

+ Reply to Thread

Similar Threads

  1. Database server problem
    By Xaeron in forum Free Hosting
    Replies: 2
    Last Post: 08-12-2008, 04:09 PM
  2. A problem with certificate
    By eon01 in forum Free Hosting
    Replies: 1
    Last Post: 07-31-2008, 01:27 PM
  3. DB number problem
    By lionheart8 in forum Free Hosting
    Replies: 5
    Last Post: 04-08-2008, 08:26 AM
  4. Problem uploading image (GD library problem)
    By HyDr@ in forum Free Hosting
    Replies: 1
    Last Post: 12-01-2006, 04:27 PM
  5. Ftp Timeout problem
    By ironcross77 in forum Free Hosting
    Replies: 7
    Last Post: 04-12-2005, 08:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts