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

    Join Date
    Aug 2009
    Posts
    26
    Rep Power
    0

    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
    aintcricket

    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>";
    }

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

    Join Date
    May 2005
    Location
    chertsey, a small town s.w. of london, england
    Posts
    250
    Rep Power
    86
    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.

    coothead

    Comments on this post

    • Kravvitz agrees
  4. #3
  5. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,128
    Rep Power
    4304
    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.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

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

    Join Date
    Jul 2004
    Location
    The Mews At Windsor Heights
    Posts
    5,309
    Rep Power
    2351
    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">'.
                  
    '<fieldset>'.
                  
    '<input type="submit" value="Delete" />'.
                  
    '</fieldset>'.
                  
    '</form>';
                  
    $change_btn '<form action="change.php" method="get">'.
                  
    '<fieldset>'.
                  
    '<input type="submit" value="Change" />'.
                  
    '</fieldset>'.
                  
    '</form>';

    echo 
    '<tr>'
           '<td></td>'
    .
           
    '<td>'.$change_btn.'</td>'.
           
    '<td>'.$delete_btn.'</td>'.
           
    '</tr>'
    .
    :: My blip.fm tunes :: Web Design Feeds :: Web Dev Feeds :: CheatSheets :: PHP :: MySQL :: 13 Moon FB App.

    "All matter is merely energy condensed to a slow vibration. We are all one consciousness experiencing itself - subjectively. There is no such thing as death, life is only a dream. We are the imaginations of ourselves."
    - Bill Hicks


    "Truth is hidden in the subtle nature of the heart of everything, although it is invisible. One cannot see it from inside and neither from the surface. One can only live and experience it."
    - Heart Sutra

IMN logo majestic logo threadwatch logo seochat tools logo