Jump to content

Multiple forms in a script


swatisonee

Recommended Posts

I continue to have problems with this issue - primarily relates to the the placement of the code for processing the 2nd form on a page.

This is what i wish to do:

a. Form 1 - Select a User

b. For selected user, list all the records

c. Form 2 - Choose 1 record from the list.

d. Update the record.

 

Here's what i have so far. I've just put the structure out here as the error  comes up when form 2 tries to get processed . I dont know if the issue is with the way i 've named the forms or the submit buttons. All pointers appreciated. Many thanks. Swati

 

<?

(processing form1)
===================
if($_POST['submit-user']){

$user = $_POST["user"];

$result = mysql_query("SELECT ...");
if ($myrow = mysql_fetch_array($result)) {

do {
    $xid=$myrow["Xid"];
   
//this has to be form 2
form2
=====

    
    <form method="post" action="form2.php"> // is this correct - the first form was a "self"

    printf("<tr><td><input type=\"radio\" name=\"choice\" value=%d><td>  
     <td>%s </td>
    <td>%s </td>
    </tr></p></table>",
    $xid ,
   $myrow["timein"],
    $myrow["trip"] );
}
while ($myrow = mysql_fetch_array($result));
}
   echo "</select>\n";
} 

<input type="submit" name="submit-data" value="Submit"> </p>

</form> (end of form 2)


processing form 2 - but where does it get placed ?
==================
if($_POST['submit-data']){

$sscid = $_POST["choice"];

$result11 = mysql_query("SELECT * FROM `Table` WHERE `SSCID` = $sscid ");
$myrow11 = mysql_fetch_array($result11);

process this data } // does the bracket close here or below with the bracket of form 1

?> // end processing of both forms.

<html>

<head>
</head>

<?php


} else {

?>

form1
=====
<FORM METHOD=post ACTION="<? echo $PHP_SELF ?>">

<select name="user"><option value="">[select One]

<?
$result = mysql_query("SELECT ...");
if ($myrow = mysql_fetch_array($result)) {

do {
    $userid=$myrow["Userid"];
    printf("<option value = '$userid'>
      %s", $myrow["Username"]);

  } while ($myrow = mysql_fetch_array($result));

   echo "</select>\n";
} 
?>
<input type="submit" name="submit-user" value="Submit"> </p>

</form> (end of form 1)
<?php

}

?>
</html> 

Link to comment
Share on other sites

Is this all in one file? A forms action should point to the file that is going to do the processing.

 

[ot]

$PHP_SELF has long been depricated and should no longer be used. If you want your form to post bake to itself, just leave the action blank. eg; ection=""

 

Do not use <? short tags. Use <?php always.

[/ot]

Link to comment
Share on other sites

hi:

 

yes and thats where i know i'm making a mistake but dont know how to correct it :

 

a. If Form 1 = <FORM METHOD=post ACTION="<? echo $PHP_SELF ?>"> (noted your comment on php self.- thanks)

then its result - that is the choice of user will go into Form 2

 

b. Form 2 = <form method="post" action="form2.php">  will display all the records for that user  and then one of the records will be chosen for further processing which is basically updating the data into a mysql table .

 

thanks

 

 

 

 

Link to comment
Share on other sites

Perhaps along these lines....

 

if !isset $_POST['$process']
  display form 1
     hidden field $process = 1
     post to self

if isset $_POST['$process'] AND $_POST['$process']= 1
  display form 2
     hidden field $process = 2
     post to self

if isset $_POST['$process'] AND $_POST['$process']= 2
  do your updating or whatever

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.