Read the News & Services Alerts Before Creating A Support Thread







x10Hosting Community » Site Design & Development » Programming Help » Query String - $_GET problem

Reply
Old 04-14-2009, 10:53 AM   #1 (permalink)
x10Hosting Member
 
Join Date: Oct 2007
Posts: 35
Credits: 678
iTrader: (0)
stevet70 is an unknown quantity at this point

Last Achievements
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
stevet70 is offline   Reply With Quote
Old 04-14-2009, 10:59 AM   #2 (permalink)
x10 Sophmore
 
akkudreamz's Avatar
 
Join Date: Jan 2009
Location: Jaipur, Rajasthan, India
Posts: 183
Credits: 4,681
iTrader: (0)
akkudreamz is an unknown quantity at this point

Last Achievements
Send a message via MSN to akkudreamz Send a message via Yahoo to akkudreamz Send a message via Skype™ to akkudreamz
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
akkudreamz is offline   Reply With Quote
Old 04-14-2009, 11:18 AM   #3 (permalink)
x10Hosting Member
 
Join Date: Oct 2007
Posts: 35
Credits: 678
iTrader: (0)
stevet70 is an unknown quantity at this point

Last Achievements
Re: Query String - $_GET problem

thanks, perfect!

obviously time I took a break
stevet70 is offline   Reply With Quote
Old 04-14-2009, 08:27 PM   #4 (permalink)
x10 Sophmore
 
akkudreamz's Avatar
 
Join Date: Jan 2009
Location: Jaipur, Rajasthan, India
Posts: 183
Credits: 4,681
iTrader: (0)
akkudreamz is an unknown quantity at this point

Last Achievements
Send a message via MSN to akkudreamz Send a message via Yahoo to akkudreamz Send a message via Skype™ to akkudreamz
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
akkudreamz is offline   Reply With Quote
Old 04-14-2009, 09:52 PM   #5 (permalink)
x10 Elder
 
VPmase's Avatar
 
Join Date: Nov 2007
Location: Davenport, IA, USA
Posts: 898
Credits: 669
iTrader: (0)
VPmase is an unknown quantity at this point

Last Achievements
Send a message via MSN to VPmase
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
VPmase is offline   Reply With Quote
Old 04-15-2009, 03:37 PM   #6 (permalink)
Community Advocate
 
Join Date: Mar 2008
Location: Libertatia
Posts: 1,061
Credits: 10,357
iTrader: (0)
misson is an unknown quantity at this point

Last Achievements
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.
misson is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database server problem Xaeron Free Hosting 2 08-12-2008 05:09 PM
A problem with certificate eon01 Free Hosting 1 07-31-2008 02:27 PM
DB number problem lionheart8 Free Hosting 5 04-08-2008 09:26 AM
Problem uploading image (GD library problem) HyDr@ Free Hosting 1 12-01-2006 05:27 PM
Ftp Timeout problem ironcross77 Free Hosting 7 04-12-2005 09:53 PM


All times are GMT -5. The time now is 11:52 AM.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios



Content Relevant URLs by vBSEO 3.3.0