edit delete maybe save buttons

Discussion in 'PHP' started by ianlufc, Apr 17, 2008.

  1. #1
    Hey Guys

    working on a college project....
    i have data coming onto a php page from mysql

    i want to add delete-edit-maybe save buttons for each row
    OR a check box and then one set of the buttons down d bottom

    I have the data coming back and going into a html table....
    but i have no clue how to get it into editable text boxes
    and then when a button in pressed getting that to interact with the db
    i have this piece of code (not working)

    <?php

    include("connect.php");



    {
    $result = mysql_query("SELECT name FROM test");

    $num_rows = mysql_num_rows($result);
    $itemchoice = 0;

    if (($row = mysql_fetch_array($result)) != 0)
    {
    echo "<table border=0>";

    echo "<tr bgcolor=#cccccc>
    <td align=center>NAME</td>
    </tr>";

    do
    {
    $name = $row['name'];

    $itemchoice = $itemchoice + 1;

    echo "<form method='post' action='<? $PHP_SELF ?>'>
    <tr>
    <td align='center'>
    <input disabled type='text' name='article' value='" . $name . "' size='30' maxlength='30'></td>
    <td align='center'>
    <input style='background-color:#CCFF33' type=checkbox name='item' id='$itemchoice'>
    </tr></font>";
    }

    while ($row = mysql_fetch_array($result));

    echo "<form method='post' action='testButtons.php'>";
    echo "<tr><td><input type='submit' name='delete' value='Delete'>";
    echo "<input type='submit' name='edit' value='Edit'></td></tr></table></form>";

    }

    else
    {
    echo "No records found!";
    }
    }

    if (isset($_REQUEST["delete"])){
    $sql_del = mysql_query("DELETE FROM test WHERE name = ".$HTTP_POST_VARS['$item']);

    }
    if (!mysql_query ($sql_del)) {
    $success = 0;
    $msg = 'Record could not be deleted';
    }
    else {
    $msg = 'Record for item '.$HTTP_POST_VARS['item'].' was deleted. Refreshing display...';
    }

    ?>

    ANY HELP MUCH APPRECIATED
     
    ianlufc, Apr 17, 2008 IP