Jump to content

how to differentiate which submit button user clicks???


josephChiaWY

Recommended Posts

Hi all,

 

I am a newbie in php. I have met a problem in echoing a few submit buttons using while loop. How do i differentiate which submit button is being click in order to grab the correct data. Below are a part of my codes:

 

 

Code: ( php )

while($requestMatch = mysql_fetch_array($friendRequest)){

       

      echo "<table width=425 height=130 border=0>";

      echo "<tr>";

      echo "<td width=110 class=style2>Add as Friend?? : </td>";

      echo "<td width=55 align=left valign=middle>";

      echo "<p>";

      echo "<form action='".$_SERVER['PHP_SELF'.'QUERY_STRING']."' method='post'>";

      echo "<a href='newFriendRequest.php?test="; echo $_SESSION['reqFriendEmail']; echo "'><input name=Submit type=submit value=YES style='width: 30px; height: 14px; font-family: Lucida Sans; font-size: 9px; color:#FFFFFF; background:#FF4700; font-style: normal; font-weight: normal; border:1px #FFFFFF; display: block; cursor:pointer; text-align: center;>";

      echo "</form></p></td>";

      echo "</tr>";

      echo "</table>";

      echo "<br>"; 

           

      $_SESSION['reqFriendName'] = $requestMatch['username']; 

      $_SESSION['reqFriendEmail'] = $requestEmail;

 

         

 

Note: i am doing a friend request page. The situation is when the user receives two requests and when the user click one of the "Yes" submit button. It takes the last request out of the friends request.

 

Link to comment
Share on other sites

<?php
   //maybe like that:
   if(isset($_POST['buttonname1'])) {
      echo 'result1';
   }elseif (isset($_POST['buttonname2'])) {
      echo 'result2';
   }
?>

 

I can't see any buttons in your code. Also please write your code like

<?php while($request/*something like that*/) {
?>some html code here <?php echo $_SERVER['PHP_SELF']; ?>
some html...
<?php } ?>

 

And $_SERVER['PHP_SELF'.'QUERY_STRING'] is not right. You have to write $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']. If you do it yourway it calls $_SERVER[php_SELFQUERY_STRING]. That element does not exist.

Link to comment
Share on other sites

Best way, IMO, would be to have two different submit buttons with different values.

 

<input type="submit" name="submit" value="Yes" />

<input type="submit" name="submit" value="Go" />

 

then

<?php
switch ($_POST['submit']) {
case "Yes" :
//Code for if "Yes" button is pressed
break;
case "Go" :
//Code for if "Go" button is pressed 
break;
default:
echo "No valid submit button pressed";
break;
}
?>

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.