#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7

    Form Submission Issue


    Well, everything was kind of going great, until I adjusted the form being submitted.

    First, just to build navigation of my pages, the Submit was actually just a

    <INPUT type="button" onClick="parent.location='?something=...'" />

    but when I changed it to a true Submit, and made the form tag into

    <FORM action="?loc=rolodex&action=update&id=23" type="post">

    I end up arriving at mysite.com/?selectedID=

    Case is to define items, and is running correct and setting variables correctly:
    PHP Code:
                            switch($action) {
                              case 
    "add":
                                
    $submit "Add";
                                
    $formAction "?loc=rolodex&action=create";
                                break;
                              case 
    "create":
                                
    $statement $link->prepare("INSERT INTO");
                                
    $statement->bind_param('issssssi'$_POST['companyID'], $_POST['name'], $_POST['position'], $_POST['number'], $_POST['type'], $_POST['email'], $_POST['note'], $_POST['customerID']);
                                
    $statement->execute();
                                
    $statement->bind_result($col1,$col2,$col3,$col4,$col5,$col6);
                                
    $statement->close();
                                break;
                              case 
    "edit":
                                
    $companyID $_GET['id'];
                                
    setVars();
                                
    $submit "Update";
                                
    $formAction "?loc=rolodex&action=update&id=" $companyID;
                                break;
                              case 
    "view":
                                
    $companyID $_GET['id'];
                                
    $var setVars();
                                
    $submit "Edit";
                                
    $formAction "?loc=rolodex&action=edit&id=" $companyID;
                                break;
                              case 
    "update":
                                
    $statement $link->prepare("UPDATE `rolodex` SET `CustomerID` = '?', `FLName` = '?', `Position` = '?', `Number` = '?', `Type` = '?', `E-mail` = '?', `Note` = '?' WHERE `ID` = '?'");
                                
    $statement->bind_param('issssssi'$_POST['companyID'], $_POST['name'], $_POST['position'], $_POST['number'], $_POST['type'], $_POST['email'], $_POST['note'], $_POST['customerID']);
                                
    $statement->execute();
                                
    $statement->bind_result($col1,$col2,$col3,$col4,$col5,$col6);
                                
    $statement->close();
                                break;
                            } 
    Form w/ similar inputs removed to shorten:
    Code:
                          <FORM action="<?php echo $formAction; ?>" type="post">
                            <TABLE id="profile">
                              <TR>
                                <TD>Logged in as: </TD>
                                <TD><?php echo $_SESSION['user']; ?></TD>
                                <TD><INPUT type="button" value=" Close " onClick="parent.location='?loc=rolodex'" /></TD>
                              <TR>
                                <TD><H3>Name:</H3></TD>
                                <TD colspan="2">
                                  <?php
                                    if($action == "add" || $action == "edit") {
                                      echo '<INPUT type="text" name="name" value="' . $var['name'] . '" />';
                                    } else {
                                      echo $var['name'];
                                    }
                                  ?>
                                </TD>
                              </TR>
    ............
                              <TR>
                                <TD><H3>Note:</H3></TD>
                                <TD colspan="2">
                                  <?php
                                    if($action == "add" || $action == "edit") {
                                      echo '<INPUT type="textbox" name="note" value="' . $var['note'] . '" />';
                                    } else {
                                      echo $var['note'];
                                    }
                                  ?>
                                </TD>
                              </TR>
                              <TR>
                                <TD colspan="3" align="center">
                                  <?php
                                    if($action == "edit" || $action == "view") {
                                      echo '<INPUT type="hidden" name="selectedID" value="' . $selectedID . '" />';
                                    }
                                  ?>
                                  <INPUT type="submit" value=" <?php echo $submit; ?> " />
                                </TD>
                              </TR>
                            </TABLE>
                          </FORM>
    Last edited by Triple_Nothing; February 24th, 2013 at 07:38 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    Sydney Australia
    Posts
    186
    Rep Power
    84
    Originally Posted by Triple_Nothing

    <FORM action="?loc=rolodex&action=update&id=23" type="post">
    Er, you mean method="post" don't you?

    type="post" will be ignored, and you'll get default method="get" .

    Comments on this post

    • ManiacDan agrees : Nice catch
    Last edited by BarryG; February 24th, 2013 at 10:56 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    Excellent catch, and that was my issue. Thank you very much. Always gotta love the basic stuff one looks over. ^_^
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Overlooks*

    ;-)
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo