PHP POST via HTML SUBMIT - unique value pass

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tylerg
Forum Newbie
Posts: 3
Joined: Wed Jul 14, 2004 3:42 pm

PHP POST via HTML SUBMIT - unique value pass

Post by tylerg »

Thought this would be a easy fix, but alas, no other forum has been able to help me... I will show you the code first and then explain the issue...

Code: Select all

//GET DRILLS BASED OF PYRAMID SUBCATAGORIES		
$query2 = "SELECT distinct `Drill`.`Drill_id`, `Drill`.`Drill_title`,`Sub_cat`.`Sub_desc` 
FROM `Drill`, `Catagory`, `Sub_cat`, `Drill_sub` 
WHERE `Drill`.`Drill_id` = `Drill_sub`.`Drill_id` AND `Drill_sub`.`Subcat_id` = `Sub_cat`.`Subcat_id` AND `Sub_cat`.`Subcat_id` = '$SUBCAT_ID'";							
$result2 = @mysql_query ($query2); // Run the query.		
echo"	  <form action="drill.php" method="post" >

<td valign="top"><table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#006699">
	<tr>
	    <td height="10" bordercolor="#336699" bgcolor="#42A0FF"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>SubCatagory 
Drills</strong></font></td>
	</tr>";		

IF ($row=mysql_fetch_array($result2) == 0){									
	echo"
               <tr>
	      <td align="center" height="10" bordercolor="#336699" bgcolor="#FFFFFF"><p> no sub drills </p></td>			  </tr>";		
}else{					
while ($row=mysql_fetch_array($result2)) { 			$drID=$row["Drill_id"];
	$title=$row["Drill_title"]; 	
	echo"	      
                <tr>
	       <td align="center" height="10" bordercolor="#336699" bgcolor="#FFFFFF">

<!--  PROBLEM AREA CODE -->
<input type="submit" name="drTITLE" value="$title" title="$title" >

<input type="hidden" name="drID[]" value="$drID" />

<!--  END OF PROBLEM AREA CODE -->	
       
                    </td>						</tr>";									
}
}		

echo"	
</table>
</td>
</tr>
</table>
</td>
</form>  ";

SO - As you can see, I have a SUBMIT and a HIDDEN posting. The way that it is currently working is that NAME="drID[]" POSTs the entire array of drill_id's. At present there is no way of me knowing which button was pressed, because simply EVERY button value is passed, that was looped out previously. IF I get rid of the HIDDEN input and put the VALUE of the SUBMIT as $drID, it passes 1 value just fine for me to beautifully use it on the next page... but then the LABEL of the button is a number rather than a descriptive user friendly drill TITLE which they need.... whoever invented the SUBMIT button with the VALUE showing rather than TITLE, needs a kick!!

HELP PLEASE!!


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post by johnperkins21 »

Could you create a javascript function that changes the value of a hidden field on certain button clicks, and then submits the form?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could name the submit the $drID or some combination of values like that.. then you don't require Javascript, or the hidden values.. the name could be "drID[$x]" where $x is the count of rows written to that point..
Post Reply