472,342 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

Form inside loop, need to wait till submit is activated.

I have the following.

$result=mysql_query($sql);
$nrows=mysql_num_rows($result);
for ($i=0;$i<$nrows;$i++)
{
$row_array=mysql_fetch_row($result);
echo "<form name='testform' action='ins_op.php' method='post'>";

lots of form stuff

echo "<td><input type='submit' value='Save'>";

echo "</form>";
}

I'd like to have the loop wait until the form submit is pressed before
it continues and grabs the next record from $row_array.

Right now the code displays all the records with their submit buttons.

Doing it in this form permits one query to the database to get all the
open records.

Alternative code structures would be entertained.

thanks

Sep 12 '05 #1
5 8161
It is amazing how clear errors in code logic are soooo clear when
posted on world wide bulletin boards.
As the code is written submiting the form will close the current
program and open the program in the form action.
So a form can not be the right way to tackle this.
Unless someone can come with a more elegant method, I guess I am going
to brute force this.

Sep 12 '05 #2

<rj***********@gmail.com> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com...
I have the following.

$result=mysql_query($sql);
$nrows=mysql_num_rows($result);
for ($i=0;$i<$nrows;$i++)
{
$row_array=mysql_fetch_row($result);
echo "<form name='testform' action='ins_op.php' method='post'>";

lots of form stuff

echo "<td><input type='submit' value='Save'>";

echo "</form>";
}

I'd like to have the loop wait until the form submit is pressed before
it continues and grabs the next record from $row_array.

Right now the code displays all the records with their submit buttons.

Doing it in this form permits one query to the database to get all the
open records.


why do you want to do this ? you can get all the data in one query
anyway...
Sep 12 '05 #3
Yeah, nix this query.
After reviewing the code, I am revisiting the logic flow from top down.

Sep 12 '05 #4
In article <11********************@g44g2000cwa.googlegroups.c om>,
rj***********@gmail.com wrote:
I have the following.

$result=mysql_query($sql);
$nrows=mysql_num_rows($result);
for ($i=0;$i<$nrows;$i++)
{
$row_array=mysql_fetch_row($result);
echo "<form name='testform' action='ins_op.php' method='post'>";

lots of form stuff

echo "<td><input type='submit' value='Save'>";

echo "</form>";
}

I'd like to have the loop wait until the form submit is pressed before
it continues and grabs the next record from $row_array.

Right now the code displays all the records with their submit buttons.

Doing it in this form permits one query to the database to get all the
open records.

Alternative code structures would be entertained.

thanks

I am guessing that you have a table of values and you want to be able to edit
those values one by one until every row has been edited? Consider something
like this:

<?
$q = mysql_query("select id, field from table where
status = 'new' order by id desc limit 1");
while ($r = mysql_fetch_array($q)){
print "<form action='$_SERVER[PHP_SELF]'>";
print "<input type='text' name='field' value='$r[field]' />";
print "<input type='hidden' name='id' value='$r[id]' />";
print "<input type='submit' value='Save value' />";
print "</form>";
}
?>

This will present a form to edit the last entry in the database. You could of
course edit multiple fields at the same time:

<form action='<?=$_SERVER[PHP_SELF] ?>'>
<?
$q = mysql_query("select id, field from table where
status = 'new' order by id desc");
while ($r = mysql_fetch_array($q)){
print "<input type='text' name='field[{$r[id]}]' value='$r[field]' />";
}
?>
<input type='submit' value='Save value' />
</form>

And then handle $_GET["field"] which is an array.
--
Sandman[.net]
Sep 12 '05 #5
rj***********@gmail.com wrote:
: I have the following.

: $result=mysql_query($sql);
: $nrows=mysql_num_rows($result);
: for ($i=0;$i<$nrows;$i++)
: {
: $row_array=mysql_fetch_row($result);
: echo "<form name='testform' action='ins_op.php' method='post'>";

: lots of form stuff

: echo "<td><input type='submit' value='Save'>";

: echo "</form>";
: }

: I'd like to have the loop wait until the form submit is pressed before
: it continues and grabs the next record from $row_array.

The problem is that you are completely misunderstanding the way this all
works.

Your script can output exactly one page. Then your script will exit.

Sometime after that the user will receive that page from the network, and
be able to see it on their browser screen.

They will look at the page and decide what to do, perhaps deciding to
press the SUBMIT button. While they are looking at the page there is _no
_program _running on the web server. Your script is not running, it
exited long before the user even starts to read the page.

When the user presses the SUBMIT button the web server will receive the
data and start up a new process to handle it. It might start the same
script as the last time, but the script itself doesn't "know" that. Your
script simply starts at the beginning each time it runs.

There are many ways and styles to handle this, but the first issue is just
understanding it.

One way to handle this is to set a hidden field in the first form that can
be used to tell what stage the user has gotten to. This is easy to
understand so I will show it. It is not alway the best way, but I think
it is easy to understand.

<?php # untested example

$where_are_we = _REQUEST['where-are-we'];
$submit_action = _REQUEST['submit'];

if ($where_are_we == '')
{
# the user has not yet visited the form at all
?>
<form action='this_script.php'>
<input type='hidden' name='where-are-we' value='1'>
<input type='submit' name='submit' value='button-one'>
<input type='submit' name='submit' value='button-two'>
</form>
<?php
}

elseif ($where_are_we == '1')
{
# The hidden field value shows that the user must be
# filling in the form created above. That form was
# created in the past. It may or may not have been
# created by this script, we have no way to know.

if ($submit_action == 'buton-one')
{
?>
<form action='this_script.php'>
<input type='hidden' name='where-are-we' value='2'>
<input type='submit' name='submit' value='confirm'>
<input type='submit' name='submit' value='ignore'>
</form>
<?php
}

else
{
?>
<form action='this_script.php'>
<input type='hidden' name='where-are-we' value='3'>
<input type='submit' name='submit' value='doit'>
<input type='submit' name='submit' value='more'>
</form>
<?php
}
}

elseif ($where_are_we == '2')
...
elseif ($where_are_we == '3')
...
...etc etc etc...
Note: personally I rarely do it quite this way. I think it is easier if
the submit button has unique values for every possible action. Then you
don't need a field like 'where_are_we', you simply check what action the
submit button has requested and try to do that action. If no action is
requested then that indicates the user has not yet seen the form, so in
that case you show the first form they need to see.

Each time the script runs it does one action. Each time it runs it has to
check that it has all the correct input to do that one action. Each time
it runs it has to check if a user is logged-in, if you are using logins.

--

This programmer available for rent.
Sep 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a...
5
by: Jack | last post by:
Hi I am trying to test a form as to its correct action. I am facing two problems. 1) When I click the submit button, the...
6
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the...
3
by: fh1996 | last post by:
Form.Owner and Form.Parent, what's the difference between them? Form.ShowDialog() and Form.Show(), when to use which? Form.Activated(), what...
10
by: Kathy Burke | last post by:
HI. in asp.net app, I have an xmlDocument that I transform to the client html. Using xsl I create a few textboxes to capture user input. Each of...
2
by: thechaosengine | last post by:
Hi all, Simple problem: I have a simple form and a submit and cancel image button underneath. I also have a logout image button at the top...
10
by: B-Dog | last post by:
I want to run something once my form in completely loaded and drawn but running at the end of form load doesn't do I guess cause of the large...
3
by: raj chahal | last post by:
Hi there i have created a registration page containing a form than sends username password to an asp processing page. If the user exists it sends...
26
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.