SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member Zan15's Avatar
    Join Date
    Jun 2004
    Location
    Taiwan
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Running PHP and SQL commands from a Form Button

    I was wondering how I can run PHP code to delete a mysql entry from a standard button on a php Form. The button code is:

    <input type="submit" name="Submit" value="Submit">

    so would It be somthing like

    <input type="submit" name="<?php code here ?>" value="Submit">

    I tried that and it didnt work maybe I'm doing somthing wrong.

    Bascily what I'm doing is hacing my script display the contents of a database with a button next to each row saying delete and I want the button to be able to del the row when clicked my full code is:

    <?php
    mysql_connect();
    mysql_select_db( "Songs" );
    $query = "SELECT * FROM `titles` ";
    $result = mysql_query( $query );
    $num_rows = mysql_num_rows( $result );
    print "<p align = \"center\">Songs in DataBase: $num_rows <P>";
    print "<table border=1 align = \"center\">\n";
    while ( $a_row = mysql_fetch_row( $result) ) {

    print "\t<td>Name: <a href = \"$a_row[2]\">$a_row[1]<br></td>\n";
    print "\t<td>Type: $a_row[3]</td>\n";
    print "\t<td>Group: $a_row[4]</td>\n";
    print "\t<td><input type=\"Submit\" name=\"Delete\" value=\"Delete\"></td>\n";
    print "</tr>\n";
    }
    print "</table>\n";

    $sql = "DELETE FROM 'titles' WHERE 'name' = 'test'";
    mysql_query($sql);
    mysql_close();
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2004
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In order to achieve this, I recommend you read the chapters of the book "Building a database driven website using PHP and MySQL" which are posted on the articles part of the SitePoint Network. There you find the solution to this problem. It is a part of the 4th chapter, which is on publishing MySQL data on the web.
    If you would rather skip reading the entire chapter (which I would not recommend), you can find the solution to this problem here.

  3. #3
    SitePoint Member Zan15's Avatar
    Join Date
    Jun 2004
    Location
    Taiwan
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •