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
https://forums.phpfreaks.com/topic/219774-multiple-forms-in-a-script/
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]

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

 

 

 

 

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.