By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,712 Members | 1,548 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,712 IT Pros & Developers. It's quick & easy.

Programming problem

P: n/a
KM
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)
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
KM wrote:
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


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
Jul 17 '05 #2

P: n/a
"KM" <ma****@czd.orgy.uk> wrote in message
news:10***************@sabbath.news.uk.clara.net.. .
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)


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
Jul 17 '05 #3

P: n/a
KM
KM wrote:
Hi,
Can anyone give me some help on how to get around this.


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

Jul 17 '05 #4

P: n/a
KM wrote:
[...] 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.


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
Jul 17 '05 #5

P: n/a
KM wrote:

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


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
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.