Jump to content

[SOLVED] posting from a drop down


jaredclance

Recommended Posts

Ok, so what I am trying to do, is populate a drop down list with nicknames from the database, then the user will select a name, hit approve and it will update the selected person in the database.

 

All of my code works, and if I insert a specific name into the approval query it works, I just don't know how make the update query know which name I have selected from the drop down.

 

It all works, I just don't know what to put for the update query NickName, I bolded the part that I am unsure about.

 

$approvalQuery = mysql_query("SELECT ID, NickName, Coach_Name, Email FROM `Profiles` WHERE Status='Approval' AND `Coach_Name`='{$p_arr['Coach_Name']}'");

 

$nameQuery = mysql_query("SELECT Coach_Name, NickName, Status FROM `Profiles` WHERE `ID`='{$p_arr['ID']}'");

$arrName = mysql_fetch_assoc( $nameQuery );

?>

</td>

</tr>

<?

if ($arrName["Coach_Name"] == $arrName["NickName"]){

?>

    <tr> 

  <td>Approvals: </td>

          <td>

<?

          echo "<select name=\"NickName\">";

          echo "<option size =30 selected>Select</option>";

          if(mysql_num_rows($approvalQuery))

          {

        while($myrow = mysql_fetch_assoc($approvalQuery))

        {

        echo "<option>$myrow[NickName]</option>";

        }

        }

        else {

        echo "<option>No Names Present</option>";

        }

?>

          </td>

</tr>

</td>

<td valign="top" align="left" class="control_panel_td_2">

<form method="post" action="member.php">

<input type="submit" value="Approve" name="Approve">

<input type="submit" value="Deny" name="Deny">

</form>

</td>

<?

}else{

echo "No Pending Students";

}

?>

</tr>

<?

//Approves user account activation

if(isset($_POST['Approve']))

  {

    mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$myrow['NickName']}'") or die (mysql_error());

}

Link to comment
Share on other sites

But if I change the update query to something like

 

  //Approves user account activation

  if(isset($_POST['Approve']))

    {

    mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = 'jared'") or die (mysql_error());

  }

 

Instead of

 

  //Approves user account activation

  if(isset($_POST['Approve']))

    {

    mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$myrow['NickName']}'") or die (mysql_error());

  }

 

Then it all works exactly how I want it to.

Link to comment
Share on other sites

Still doesn't work  :(

 

<form method="post" action="member.php">

<?

          echo "<select name=\"NickName\">";

          echo "<option size =30 selected>Select</option>";

          if(mysql_num_rows($approvalQuery))

          {

        while($myrow = mysql_fetch_assoc($approvalQuery))

        {

        echo "<option>$myrow[NickName]</option>";

        }

        }

        else {

        echo "<option>No Names Present</option>";

        }

?>

          </td>

</tr>

</td>

<td valign="top" align="left" class="control_panel_td_2">

<input type="submit" value="Approve" name="Approve">

<input type="submit" value="Deny" name="Deny">

</form>

</td>

<?

}else{

echo "No Pending Students";

}

?>

</tr>

<?

//Approves user account activation

if(isset($_POST['Approve']))

  {

    mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$myrow['NickName']}'") or die (mysql_error());

}

Link to comment
Share on other sites

<form method="post" action="member.php">
<?
                echo "<select name=\"NickName\">";
                echo "<option size =30 selected>Select</option>";
             if(mysql_num_rows($approvalQuery))
             {
                while($myrow = mysql_fetch_assoc($approvalQuery))
             {
                echo "<option>$myrow[NickName]</option>";
             }
             }
             else {
                echo "<option>No Names Present</option>"; 
             }   
?>
          </td>
   </tr>
   </td>
   <td valign="top" align="left" class="control_panel_td_2">
         <input type="submit" value="Approve" name="Approve">
         <input type="submit" value="Deny" name="Deny">
         </form>
   </td>
<?
      }else{
         echo "No Pending Students";
      }
?>
   </tr>   
<?
   //Approves user account activation
   if(isset($_POST['Approve']))
     {
    mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$_POST['NickName']}'") or die (mysql_error());
   }

 

You have to set the $_POST[] array, not the $myrow[] array.

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.