Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
    $friendRequests = ("SELECT * FROM zahtjevi_prijatelja WHERE user_to='".$_SESSION['ID']."'");
    $res = mysql_query($friendRequests) or die(mysql_error());
    if (mysql_num_rows($res) ==0) {
     echo "You have no friend Requests at this time.";
     $user_from = "";
    }
    else
    {


     while ($get_row = mysql_fetch_assoc($res)) {

While return all friend requests ,and create form for every request. Form is in while-loop. What i want to do is that if I press submit button for one of requests that i get, add only for pressed to database, but in my case all requests are added. Its because form name is always the same in while-loop so i need some how dynamically change name of form if there is more friend requests.

      <form action="friendRequest.php" method="post" id="myForm"
    enctype="multipart/form-data">



    <input type="submit" name="acceptrequest" value="Accept Request">
    <input type="submit" name="ignorerequest" value="Ignore Request"><br>


    </form>
<?php
    }
?>
share|improve this question
    
Are you sure you're not overthinking your implementation logic? as a simple table with radio buttons & a button at the bottom would be a cost/time effective implementation –  Daryl Gill 1 hour ago
    
You want to send accept or reject to only one person isn't it? @Emil Balint –  Muhammad Ashikuzzaman 47 mins ago
    
Yes,that's correct.@MuhammadAshikuzzaman –  Emil Balint 27 mins ago

2 Answers 2

Maybe a multiselect dropdown to accept multiple requests or a single one at a time?

<form>
<label for="accept_request"
<select multiple name="accept_request[]">
  <option value="1">Friend Request 1</option>
  <option value="2">Friend Request 2</option>
  <option value="3">Friend Request 3</option>
  <option value="4">Friend Request 4</option>
</select>

</form>
share|improve this answer

Use this: Will work better.

 <form action="friendRequest.php" method="post" id="myForm" enctype="multipart/form-data">

    <input type="submit" name="<?php echo $_SESSION['ID'].'acceptrequest'; ?>" value="Accept Request">
    <input type="submit" name="<?php echo $_SESSION['ID'].'ignorerequest'? " value="Ignore Request"><br>

 </form>

In friendRequest.php use this:

 $a=$_SESSION['ID'].'acceptrequest'; 
 $b=$_SESSION['ID'].'ignorerequest';
 if(isset($_POST[$a]))
    {
    ..................... 
    }
if(isset($_POST[$b]))
    {
    ..................... 
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.