Jump to content

Multiple inserts from one form


fife

Recommended Posts

Hi all.

 

Im trying to insert from one form 3 items of data into to different tables.  I will post the code as most of my notes are in there but first.......

 

What is happening is the form is filled in then the first part of the form where it updates my clubs table with category ID's works fine. Nothing in the

if ($result) { }

seems to run.

I have create some fake groups so the drop down is populated with groups already created and I have tried to select one of these groups so it can be entered into the clubs table and nothing.  No errors just no answers.  Does anybody no what I am doing wrong?

 

 

first Ill post the form and the querys that make fields in the form... 

 

Querys

//gets
$validation = $_GET['new_club'];
//Querys
    $qGetClub = "SELECT * FROM clubs WHERE validationID = '$validation'"; 
$rGetClub = mysql_query($qGetClub);
$Club = mysql_fetch_array($rGetClub);
//Query for category by name
$qGetCat = "SELECT * FROM club_category WHERE catID = ".$Club['cat']."";
$rGetCat = mysql_query($qGetCat);
$CatName = mysql_fetch_array($rGetCat);
//query for related sub categorys.
$qGetSub = "SELECT * FROM sub_categorys WHERE catID =".$Club['cat']."";
$rSubCat = mysql_query($qGetSub);
// query for groups created
$Groupq	=	mysql_query("SELECT * FROM groups WHERE memberID = '".$User['memberID']."'");

 

 

  then we have the form

 

<form action="" method="post"  id="insert_clubfrm">
					  
					                        <tr valign="baseline">
                                <td colspan="2"  valign="top"><br/><p>Your Chosen category was <strong><?php echo $CatName['categorys'];?></strong> Please select a sub category.</p><br></td>
                              </tr>
                              
                              <tr valign="baseline">
                                <td width="132"  valign="top" >Club Sub Category:</td>
                                <td width="256"  valign="top"  ><select name='subcat'>
                            <option value="None">Please Select One</option>
								<?php while ($New_SubCat = mysql_fetch_assoc($rSubCat)) { ?>

                                <option value="<?php echo $New_SubCat['subID']; ?>"><?php echo $New_SubCat['sub_categorys']; ?></option>"<?php  }  ?>

							</select>
  </td>
                              </tr>
                              <tr valign="baseline">
                                 <td colspan="2"  valign="top" ><br/><p>If your sub category does not exist in the list please select "none" above and enter your new sub categroy below.</p><br></td>
                              </tr>
                              <tr valign="baseline">
                                <td  valign="top" class="left_padding">New Sub Category</td>
                                <td valign="top" class="left_padding"><input type="text" name="newSubCat" id="new_cat" value="" /></td>
                              </tr>
                              <tr valign="baseline">
                                <td colspan="2"  valign="top" class="left_padding"><br/>
                                	If you had/have more than one site and you had to give your group of companies a name what would that name be?
                                <br/></td>
                              </tr>
                              <tr valign="baseline">
                                <td  valign="top" class="left_padding">Group Name:</td>
                                <td  valign="top" class="left_padding"><label for="other_groups"></label>
                                  <select name="other_groups" id="other_groups">
                                  <option>None</option>
                                  <?php while ($group = mysql_fetch_assoc($Groupq)) { ?>
                                    <option value="<?php echo $group['groupID']; ?>"><?php echo $group['group']; ?></option>"<?php  }  ?>  
                                </select></td>
                              </tr>
                              <tr valign="baseline">
                                <td  valign="top" class="left_padding">Group Name:</td>
                                <td  valign="top" class="left_padding"><label for="new_groups"></label>
                                 <input type="text" name="new_group" value="">

  
</td>
                              </tr>
                                                        <tr valign="baseline">
                                <td valign="top" nowrap="nowrap"> </td>
                                <td valign="top"><div align="left">
                                  <input type="submit" id="insert_clubbtn1" name="insert_clubbtn1" value="Insert record" />
                                </div></td>
                              </tr>
                            </table>
                            </form>

 

 

 

 

now the code to make the form work...

 


if(isset($_POST['insert_clubbtn1'])){ 
//Process data for validation     
$subcat    	= trim($_POST['subcat']);  
$NewSubCat = trim($_POST['NewSubCat']); 

$otherg	=	trim($_POST['other_groups']);
	$newg	=	trim($_POST['new_groups']);     
//Prepare data for db insertion      
$newg	=	mysql_real_escape_string($newg);  
$subcat			= mysql_real_escape_string($subcat); 
//find the new category 
//insert
$result = mysql_query("UPDATE clubs  SET 
`sub_category`			=	'$subcat'
WHERE validationID ='$validation'") or die(mysql_error());
if ($result) {		
	//if an item other than none from the list is selected then update the club with an ID relating to the group it belongs to			
if ($otherg !=='None') { $groupsq = mysql_query("UPDATE `clubs` SET groupID ='$otherg' WHERE validationID ='$validation')") or die (mysql_error()); }
// If none is selected then $newg must have a value so create a new group in the groups table and then on the next page I will add the group in the club table 		
if ($otherg == 'None')	{
$groupsq = mysql_query("INSERT INTO `groups` (memberID, group, clubID) VALUES ('".$User['memberID']."', '$newg', ''".$Club['clubID']."')");
}	}


if ($NewSubCat !="") { mail("email","New Sub Category Request","Dear Owner,
\n\nThe club in the name of $name with a validation code of $validationID would like a new sub category called $new_cat\n\n  
\nTeam Me\n\n\n\n"); }

$url = "/create/create_clubp3.php?new_club=$validation";  
header("Location: $url");     




Link to comment
https://forums.phpfreaks.com/topic/238073-multiple-inserts-from-one-form/
Share on other sites

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.