PHP help needed.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vagabond
    New Member
    • Apr 2006
    • 17

    PHP help needed.

    I have a section of code that seems to work untill I go to get the result but can't see what I am doing wrong.

    Code:
    function Edit_User(){
    
    global $conn;
    Connect_to_db();
    
    $sql = "SELECT * FROM user";
    $result = mysql_query($sql, $conn) or die(mysql_error());
    
    ?>
    <form method="post" action="../news/news.php?page=Edit_Selected_User" name="EditUser">
    <select name="selectuser">
    <?php
    
    while ($newArray = mysql_fetch_array($result)){
    
      $editname = $newArray['name'];
      printf ("<option value=\"$result\">$editname</option>");
    }
    ?>
    </select>
    <input type="submit" name="edit" value="Edit">
    </form>
    <?php
    
    mysql_close();
    }
    The above part seems to work however when I try to get the data returned from the $_POST it's always blank.

    Code:
    if ($_GET[page] == "Login"){
      Get_Login_Page();
    }
    else if($_GET[page] == "Edit_Selected_User"){
     $a = $_Post[selectuser];
     echo $a;                        //  This always returns nothing.
    } 
    else if($_GET[page] == "Edit_User"){
      Edit_User();
    }
    else if($_GET[page] == "Adduser"){
      Add_User_Menu();
    }
    else if($_GET[page] == "Save_New_User"){
      Save_New_User();
    } else {
      echo "Nothing to do!";
    }
    I know I am just doing something stupid wrong but can't seem to find out what.
  • Vagabond
    New Member
    • Apr 2006
    • 17

    #2
    I found the error here

    $a = $_Post[selectuser];

    Should be:

    $a = $_POST[selectuser];

    It's still not quite working the way I wanted it to because it returns the resource ID instead of a user name but I will try to play with it more and see if I can figure that one out.

    Comment

    • Vagabond
      New Member
      • Apr 2006
      • 17

      #3
      I also got the resource ID problem figured out. Guess I didn't need help afterall. Just needed a break from coding. lol

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by Vagabond
        $a = $_POST[selectuser];
        If selectuser is a string it is safer to write this as[php]$a = $_POST['selectuser'];[/php]NOTE the added quotes. This is because without the quotes the PHP engine first searchs to see if selectuser is a defined symbol.
        Last edited by Banfa; May 3 '06, 10:35 AM. Reason: correcting case of _POST

        Comment

        Working...