Forum Moderators: coopster

Message Too Old, No Replies

value of hidden field

Updating current value on PHP page

         

thorin

1:30 pm on May 12, 2007 (gmt 0)

10+ Year Member



I am having some trouble with a hidden field, I have three drop down boxes for the day/month/year, when this are selected it updates a hidden field with the values for posting to the mysql table.

I have the following snippets that are applicable :-
In the session_start() part

$_SESSION['datefished'] = $datefished;

$datefished = $_POST['fldYear'] . '-' . $_POST['fldMonth'] . '-' . $_POST['fldDay'];

and for the hidden field :-

<input name="datefished" type="hidden" id="datefished" value="<?php echo $_SESSION['datefished'];?>" />

The problem seems to be that the date value that appears in the mysql table, is the date from the previous entry and not the current one!

I am seriously confused by this, has anyone got any idea's where I am going wrong?

Birdman

1:47 pm on May 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would think these two lines are in the wrong order:

$_SESSION['datefished'] = $datefished;

$datefished = $_POST['fldYear'] . '-' . $_POST['fldMonth'] . '-' . $_POST['fldD'];

You need to set the value for $datefished first:

$datefished = $_POST['fldYear'] . '-' . $_POST['fldMonth'] . '-' . $_POST['fldD'];

$_SESSION['datefished'] = $datefished;

thorin

1:50 pm on May 12, 2007 (gmt 0)

10+ Year Member



Many thanks for the reply, I reversed the order as you suggested, but I still get the same answer!

Birdman

2:03 pm on May 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whenever I have mysql problems I echo the sql statement to the screen to evaluate it for problems.

$sql = "INSERT INTO...";

die($sql); // remove after resolving problem

$result = mysql_query($sql);

Arno_Adams

7:15 am on May 14, 2007 (gmt 0)

10+ Year Member



Hi,

The value of the session var (and the hidden field) gets updated when you post the form. But then it's too late to get that value in your sql statement.

Just concat the 3 values from the form fields to form the date.

$datefished = $_POST['fldYear'] . '-' . $_POST['fldMonth'] . '-' . $_POST['fldDay'];

HTH, AA

ItzFX

2:54 am on May 15, 2007 (gmt 0)

10+ Year Member



It sounds like you want to update within the page (eg, right when the user makes a change, not when they submit). You'll need to use AJAX for something like that