Connecting Tech Pros Worldwide Forums | Help | Site Map

Programming problem

KM
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,

I am not sure if this is a HTML or PHP problem, so please bear with me.

I have a PHP/HTML script to create and update records in a database.
On page1.php, I ask the user for a reference number. Pressing Submit button
launches page2.php
On page2.php I check that this is unique and if so, I create a new record in
the database. On the same page, I ask the user to complete the remainder of
the fields. Press Submit button to take you to page 3.
On page 3, I need to update the database record with the newly completed
fields. The problem is that the variable (reference number) I created in
page 1 is not carried to page 3. So the update doesn't happen.

Can anyone give me some help on how to get around this.

Apache 1.3.8, PHP 4

Thanks

Martyn

--
Martyn

(remove the 2nd "Y" to reply)



Elliott Back
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Programming problem


KM wrote:[color=blue]
> Hi,
>
> I am not sure if this is a HTML or PHP problem, so please bear with me.
>
> I have a PHP/HTML script to create and update records in a database.
> On page1.php, I ask the user for a reference number. Pressing Submit button
> launches page2.php
> On page2.php I check that this is unique and if so, I create a new record in
> the database. On the same page, I ask the user to complete the remainder of
> the fields. Press Submit button to take you to page 3.
> On page 3, I need to update the database record with the newly completed
> fields. The problem is that the variable (reference number) I created in
> page 1 is not carried to page 3. So the update doesn't happen.
>
> Can anyone give me some help on how to get around this.
>
> Apache 1.3.8, PHP 4
>
> Thanks
>
> Martyn
>[/color]

Add the reference number as a hidden form field in page 2, and get it in
page 3. Then you can carry it around with you!

--
Thanks,
Elliott C. Bäck
---------------------------------
www.elliottback.com/blog/
www.spreadIE.com
kingofkolt
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Programming problem


"KM" <martyn@czd.orgy.uk> wrote in message
news:1097693240.9378.0@sabbath.news.uk.clara.net.. .[color=blue]
> Hi,
>
> I am not sure if this is a HTML or PHP problem, so please bear with me.
>
> I have a PHP/HTML script to create and update records in a database.
> On page1.php, I ask the user for a reference number. Pressing Submit[/color]
button[color=blue]
> launches page2.php
> On page2.php I check that this is unique and if so, I create a new record[/color]
in[color=blue]
> the database. On the same page, I ask the user to complete the remainder[/color]
of[color=blue]
> the fields. Press Submit button to take you to page 3.
> On page 3, I need to update the database record with the newly completed
> fields. The problem is that the variable (reference number) I created in
> page 1 is not carried to page 3. So the update doesn't happen.
>
> Can anyone give me some help on how to get around this.
>
> Apache 1.3.8, PHP 4
>
> Thanks
>
> Martyn
>
> --
> Martyn
>
> (remove the 2nd "Y" to reply)
>
>[/color]

Try using a hidden field in page2.php's form. For example, if you named the
reference number textbox "refnum", put this line in your form in page2.php:

<input type="hidden" name="refnum" value="<?php print $_REQUEST['refnum'];
?>">

Then, on page3.php, access the reference number using $_REQUEST['refnum'].
(Or use $_POST/$_GET depending on what method you're using.)

- JP


KM
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Programming problem


KM wrote:[color=blue]
> Hi,
> Can anyone give me some help on how to get around this.
>[/color]

I have managed to do this using cookies - not ideal but got me out of a
hole.
But any other suggestions would be welcomed
--
Martyn



Pedro Graca
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Programming problem


KM wrote:[color=blue]
> [...] The problem is that the variable (reference number) I created in
> page 1 is not carried to page 3. So the update doesn't happen.
>
> Can anyone give me some help on how to get around this.[/color]

Save the reference number in a session variable.

<?php // page1.php
session_start();
$_SESSION['ref_number'] = '123456';

// ... whatever
echo '<a href="page2.php">go to page 2</a>';
?>


<?php // page2.php
// ... whatever
echo '<a href="page3.php">go to page 3</a>';
?>


<?php // page 3
session_start();
echo 'Reference number: ', $_SESSION['ref_number'];
?>


--
USENET would be a better place if everybody read:
http://www.expita.com/nomime.html
http://www.netmeister.org/news/learn2quote2.html
http://www.catb.org/~esr/faqs/smart-questions.html
Shawn Wilson
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Programming problem


KM wrote:[color=blue]
>
> I have managed to do this using cookies - not ideal but got me out of a
> hole.
> But any other suggestions would be welcomed[/color]

As someone else suggested, go with sessions. The problem with hidden variables
and cookies is that they can easily be faked. For instance, if you have
reference numbers 235, 345 and 111 in your db, then I could go directly to page
2 with http://yourdomain.com/page2.php?refnum=111 and change values that are
already there from another user. Or, with slightly more work, I could write a
PHP script to go directly to page 2 while sending a cookie containing the
number.

And, as a side note, I hope you have a good reason for making the user enter a
reference number (i.e. it applies to an existing reference number from another
system, etc.). I hope you're not just making them think of one so you don't
have to code it. :o)

Shawn


--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
Closed Thread