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
https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/
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.

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());

}

<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.

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.