Forum Moderators: coopster

Message Too Old, No Replies

Problem inserting url variable into table

         

stephen675

2:31 pm on Jan 1, 2009 (gmt 0)

10+ Year Member



Hi guys,

I'm stumped... Although I have only about 2 weeks worth of PHP experience this should be a no brainer but doesn't seems to work... Here's my dilemma:

- I have a table where one of the cells in the table links to a poll html/php page
- when the link in the cell is selected, a var (foo) is passed into the url so the link looks like www.website.com/poll.php?foo=bar
- this poll page contains radio buttons and when the user submits the poll, I want the radio button info and the var to get inserted into a mysql table. I have no probelms inserting the radio button info but for some reason I cannot insert the var... :(

Following are snippets of the code:
<?php
$c1 = $_POST["books"];
$c2 = $_POST["magazines"];

$item = $_GET['foo'] <- pulling in the variable from url

if (!isset($_POST['submit])) {
?>
<- html code for radio button goes here
<- radio button form also goes here
<?
} else {
require_once("db.php");

if(isset($_POST['books'])) {$c1=$_POST['books']};
if(isset($_POST['magazines'])) {$c1=$_POST['magazines']};
}
mysql_query{"insert INTO poll (update_dt,var,book,magazine) values(now(),'$item','$books','magazines')");
}
?>

The '$books' and '$magazines' variables get inserted into the 'poll' table but '$item' does not...

Any help is greatly appreciated.

Thanks,

Shoolace

Mahabub

3:11 pm on Jan 1, 2009 (gmt 0)

10+ Year Member



Dear stephen675,

I reviews your code. You Get the value of foo in poll.php and after then you submit the form in another page or the same page then you lost the value of foo. I think you used a form on poll.php which should be the like the below one.

<form id="something" method="POST" action="some.php?foo=<? echo $_GET["foo"] ?>">

Thanks
Mahabub

[edited by: Mahabub at 3:20 pm (utc) on Jan. 1, 2009]

stephen675

3:41 pm on Jan 1, 2009 (gmt 0)

10+ Year Member



Mahabub,

It worked! Thank you soooo much! I was struggling with this for most of the day yesterday... :)

Stephen