Connecting Tech Pros Worldwide Help | Site Map

Passing on a value to a SUBMIT button - can it be done?

Marcel
Guest
 
Posts: n/a
#1: Sep 30 '05
I'm creating an application with which I can update values in a MySQL
database.
Each row of the database table is a web page with a form. After updating the
fields, the new values are passed on the database table by pressing the
Submit-button. So far, no problems. Then I want to go on to the next page,
so I was hoping that something like this would work:

echo '<form method="GET" action ="de.php?pageno=5">';

But it doesn't. I keep on coming back to page 1.
What should I be doing?

Thanks, Marcel



NC
Guest
 
Posts: n/a
#2: Sep 30 '05

re: Passing on a value to a SUBMIT button - can it be done?


Marcel wrote:[color=blue]
>
> I'm creating an application with which I can update values in a MySQL
> database.
> Each row of the database table is a web page with a form. After updating the
> fields, the new values are passed on the database table by pressing the
> Submit-button. So far, no problems. Then I want to go on to the next page,
> so I was hoping that something like this would work:
>
> echo '<form method="GET" action ="de.php?pageno=5">';
>
> But it doesn't. I keep on coming back to page 1.
> What should I be doing?[/color]

You should define a hidden field somewhere in the form. Something
like this:

<input type="hidden" name="pageno" value="<?php
echo $_GET['pageno'];
?>">

Cheers,
NC

Ramon
Guest
 
Posts: n/a
#3: Sep 30 '05

re: Passing on a value to a SUBMIT button - can it be done?


Hmmm... it appears you are fairly green at this :)

But anyway...

To move to another page you have a few options.

Option 1: Do your db operations on the page you are going to.

or

Option 2: Redirect from the page where you are currently performing your
Database operations, using header("Location: destination_page.php");

Hope that helps.

D.

Marcel wrote:[color=blue]
> I'm creating an application with which I can update values in a MySQL
> database.
> Each row of the database table is a web page with a form. After updating the
> fields, the new values are passed on the database table by pressing the
> Submit-button. So far, no problems. Then I want to go on to the next page,
> so I was hoping that something like this would work:
>
> echo '<form method="GET" action ="de.php?pageno=5">';
>
> But it doesn't. I keep on coming back to page 1.
> What should I be doing?
>
> Thanks, Marcel
>
>
>[/color]
Siv Hansen
Guest
 
Posts: n/a
#4: Sep 30 '05

re: Passing on a value to a SUBMIT button - can it be done?


> Marcel wrote:[color=blue]
>[color=green]
>> I'm creating an application with which I can update values in a MySQL
>> database.
>> Each row of the database table is a web page with a form. After
>> updating the
>> fields, the new values are passed on the database table by pressing the
>> Submit-button. So far, no problems. Then I want to go on to the next
>> page,
>> so I was hoping that something like this would work:
>>
>> echo '<form method="GET" action ="de.php?pageno=5">';[/color][/color]

write echo '<form method="get" action="">'

and then change your code in de.php to
if(isset($_REQUEST['page'])){
//connect to your database
//query the database for page where id=the value in $_REQUEST['page']
//retreive html-page and display

}else{
//display normal de.php
}[color=blue][color=green]
>>
>> But it doesn't. I keep on coming back to page 1.
>> What should I be doing?
>>
>> Thanks, Marcel
>>[/color][/color]

There was a comment on hidden fields. Variables carried by urls are easy
to manipulate,
and although it looks cool (yes it does) perhaps you should avoid them.
Then the method is
post, not get, but the code in de.php remains (since you use the
REQUEST-method which accepts both POST and GET)
John Dunlop
Guest
 
Posts: n/a
#5: Sep 30 '05

re: Passing on a value to a SUBMIT button - can it be done?


Marcel wrote:
[color=blue]
> <form method="GET" action ="de.php?pageno=5">[/color]

I can't see anything in the HTML4.01 spec which forbids this. It's
valid, that's easily checkable; it also complies with at least one
reading of the prose. What's left is to see what browsers make of it.

On submission, according to the spec, a question mark is appended to the
value of the action attribute and the form data set (name/value pairs) is
then appended. Here, the action URL already has a question mark, so
appending another question mark gives a URL with two question marks, e.g.

http://host.invalid/foo?bar=1?baz=2

If arg_separator is the ampersand '&', the first and second arguments will
combine and PHP will recognise only one variable: name 'bar', value
'1?baz=2'.

As to browsers, YMMV.

--
Jock
Marcel
Guest
 
Posts: n/a
#6: Oct 2 '05

re: Passing on a value to a SUBMIT button - can it be done?



"Siv Hansen" <sivh@broadpark.no> wrote in message
news:433c8e55$1@news.broadpark.no...[color=blue][color=green]
> > Marcel wrote:
> >[color=darkred]
> >> I'm creating an application with which I can update values in a MySQL
> >> database.
> >> Each row of the database table is a web page with a form. After
> >> updating the
> >> fields, the new values are passed on the database table by pressing the
> >> Submit-button. So far, no problems. Then I want to go on to the next
> >> page,
> >> so I was hoping that something like this would work:
> >>
> >> echo '<form method="GET" action ="de.php?pageno=5">';[/color][/color]
>
> write echo '<form method="get" action="">'
>
> and then change your code in de.php to
> if(isset($_REQUEST['page'])){
> //connect to your database
> //query the database for page where id=the value in $_REQUEST['page']
> //retreive html-page and display
>
> }else{
> //display normal de.php
> }[color=green][color=darkred]
> >>
> >> But it doesn't. I keep on coming back to page 1.
> >> What should I be doing?
> >>
> >> Thanks, Marcel
> >>[/color][/color]
>
> There was a comment on hidden fields. Variables carried by urls are easy
> to manipulate,
> and although it looks cool (yes it does) perhaps you should avoid them.
> Then the method is
> post, not get, but the code in de.php remains (since you use the
> REQUEST-method which accepts both POST and GET)[/color]

Hello again,
I've been trying to implement what was said, but it just doesn't work here..
For the moment I go for the suggestion with a Hidden field in the form,
because that looks the most simple one, and I'm only using this application
at home, it's only for me and not for anybody else..
I'm testing this in IE6 with IIS.
Loading the page goes ok, and the pageno echoes as '1'.
Then I hit submit, the pageno echoes as blank and I get the following
notice: Notice: Undefined index: pageno in
c:\\inetpub\\wwwroot\\picdata\\de2.php on line 39

Here's the code:

<html>
<head>
<title>Picture data entry</title>
</head>
<body>
<div id="container">

<?php

/*initialize pageno */
/* if there is a pageno then it must be one higher then the last time */

if (isset($_GET['pageno']))
{
$pageno = $_GET['pageno'];
$pageno = $pageno++;
}
else
{
$pageno = 1;
}

echo "pageno :" . $pageno;


?>

<p>
<hr align = "left">
<table>
<tr>
<td align = "center" >
<img border = "0" src = "images/01bc11.jpg ">
</td>
<td>
<form method="GET" action ="de2.php?pageno=$pageno">
<input type="text" name="pictureid" value="pictureid" READONLY>
Picture ID <BR>
<input type="text" name="year" value="year" READONLY> Year <BR>
<input type="hidden" name="pageno" value="<?php echo $_GET['pageno'];
?>">

<p>
<input type="submit" name="submit" value="Submit">
</form>
</td>
</tr>
</table>
<hr align = "left">
</div>
</body>
</html>

Thanks for any suggestion...
Marcel


Colin Fine
Guest
 
Posts: n/a
#7: Oct 2 '05

re: Passing on a value to a SUBMIT button - can it be done?


Marcel wrote:[color=blue]
> "Siv Hansen" <sivh@broadpark.no> wrote in message[/color]
[color=blue]
> Hello again,
> I've been trying to implement what was said, but it just doesn't work here..
> For the moment I go for the suggestion with a Hidden field in the form,
> because that looks the most simple one, and I'm only using this application
> at home, it's only for me and not for anybody else..
> I'm testing this in IE6 with IIS.
> Loading the page goes ok, and the pageno echoes as '1'.
> Then I hit submit, the pageno echoes as blank and I get the following
> notice: Notice: Undefined index: pageno in
> c:\\inetpub\\wwwroot\\picdata\\de2.php on line 39
>
> Here's the code:
>
> <html>
> <head>
> <title>Picture data entry</title>
> </head>
> <body>
> <div id="container">
>
> <?php
>
> /*initialize pageno */
> /* if there is a pageno then it must be one higher then the last time */
>[/color]
Here, you're checking whether there was a 'pageno' in the URL:
[color=blue]
> if (isset($_GET['pageno']))
> {
> $pageno = $_GET['pageno'];
> $pageno = $pageno++;
> }
> else
> {
> $pageno = 1;
> }
>
> echo "pageno :" . $pageno;
>
>
> ?>
>
> <p>
> <hr align = "left">
> <table>
> <tr>
> <td align = "center" >
> <img border = "0" src = "images/01bc11.jpg ">
> </td>
> <td>
> <form method="GET" action ="de2.php?pageno=$pageno">
> <input type="text" name="pictureid" value="pictureid" READONLY>
> Picture ID <BR>
> <input type="text" name="year" value="year" READONLY> Year <BR>[/color]

but here, you're not checking it!
[color=blue]
> <input type="hidden" name="pageno" value="<?php echo $_GET['pageno'];
> ?>">
>
> <p>
> <input type="submit" name="submit" value="Submit">
> </form>
> </td>
> </tr>
> </table>
> <hr align = "left">
> </div>
> </body>
> </html>
>
> Thanks for any suggestion...
> Marcel
>
>[/color]

You also need to think about your line
$pageno = $pageno++;

The 'post-increment operator' ++ means 'change this variable by adding
1, and then return the previous value' - so the line above has no net
effect!

Colin
Closed Thread