1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Rep Power

    Input action='delete.php' type='submit' does not run php file

    I am using a while function to create HTML records that reflect an SQL database. Each row of data is a form with it's own change and delete submit buttons. Then I ask the button to run the relative change.php or delete.php nothing happens. Both php's should display 'Hello World' when clicked.

    Many Thanks

    while($row = mysql_fetch_array($result))
    echo "<tr><form>";
    echo "<td>" . $row['firstname'] . "</td>";
    echo "<td>" . $row['lastname'] . "</td>";
    echo "<td>" . $row['street'] . "</td>";
    echo "<td>" . $row['city'] . "</td>";
    echo "<td>" . $row['county'] . "</td>";
    echo "<td>" . $row['postcode'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "<td>" . $row['phone'] . "</td>";
    echo "<td>" . $row['fax'] . "</td>";
    echo "<td><input action='change.php' type='submit' value='Change'></td>";
    echo "<td><input action='delete.php' type='submit' value='Delete'></td>";
    echo "</form></tr>";

  2. #2
  3. ~ bald headed old fart ~
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2005
    chertsey, a small town s.w. of london, england
    Rep Power
    Hi there aintcricket,

    action is an attribute of the form element not the input element.

    Also note that the form element may not be positioned between the tr element and the td element.


    Comments on this post

    • Kravvitz agrees
    ~ the original bald headed old fart ~
  4. #3
  5. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    USA (verifiably)
    Rep Power
    To add to what coothead said... In HTML 4 the action attribute must be specified on the form, not the submit button. (In the working draft of HTML 5, there's a new feature to allow the form's action to be specified via an attribute on submit buttons.)

    To have different actions, you must detect which submit button was used. So give each submit button a name so that the name/value pairs can be checked via a PHP script when the form is submitted.
    Spreading knowledge, one newbie at a time.

    Learn CSS. | PHP includes | HTML Validator | CSS validator

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  6. #4
  7. Banned

    Join Date
    Jul 2004
    The Mews At Windsor Heights
    Rep Power
    I don't think it's valid for a form to have a <tr> as its parent.

    There's no reason why you can't have a separate form for each button. You might want to set margins, paddings and borders to 0 for the forms and fieldset tags.
    PHP Code:
    $delete_btn '<form action="delete.php" method="get">'.
    '<input type="submit" value="Delete" />'.
    $change_btn '<form action="change.php" method="get">'.
    '<input type="submit" value="Change" />'.


IMN logo majestic logo threadwatch logo seochat tools logo