Php code help need

Discussion in 'PHP' started by indika250, Feb 13, 2012.

  1. #1
    i want create web site and i want use delete command to some recodes . but i have no idea to how to do that.i have only little knowledge of php

    first i create delete.php and send data to deletesql.php plz check this code and if any errs let me know

    <?php
    include("dbinfo.php");
    $result = mysql_query("SELECT * FROM data") or die(mysql_error());
    ?>
        <tr>
                <td><form action="deletesql.php" method="post" name="form1" target="_top" id="form1">
                  <table width="910" border="1" align="left" cellpadding="1" cellspacing="1">
                    <?php
      
    while($row = mysql_fetch_array($result)){
    
    $trackingno = $row['trackingno'];
    $picdate = $row['picdate'];
    $service = $row['service'];
    $destination = $row['destination'];
    $status = $row['status'];
    $handoverto = $row['handoverto'];
    
    $result1 = mysql_query("SELECT trackingno FROM data WHERE (id = $trackingno) ") or die(mysql_error());
    
    //$trackingno = mysql_result($result1,0,'trackingno');
      
      ?>
    
                    <tr>
                      <td width="150" align="center" valign="top"><?php  echo $trackingno ;  ?></td>
                      <td width="150" align="center" valign="top"><?php  echo $destination ;  ?></td>
                      <td width="150" align="center" valign="top"><?php  echo $status ;  ?></td>
                      <td width="150" align="center" valign="top"><?php  echo $handoverto ;  ?></td>
                      <td width="150" align="center" valign="top"><input name="trackingno" type="radio" value="$trackingno" />
                        <label>
                        <input name="Update" type="submit" id="Update" value="Delete" />
                        </label></td>
                    </tr>
                    
                    
    				<?php } ?>
                  </table>
                    </form>            </td>
              </tr>
            </table></td>
          </tr>
          
      
    PHP:

    *****************************************************************************

    then i create deletesql.php and here is the code

    <?php
    $trackingno = $_POST['trackingno'];
    include("dbinfo.php");
    
    //DELETE FROM table_name WHERE record_id=<id> 
    mysql_query("DELETE FROM data WHERE trackingno = '$trackingno' ") or die(mysql_error());
    //$result = mysql_query("SELECT * FROM data WHERE id = '$trackingno' ") or die(mysql_error());
    header('Location: delete.php');
    ?>
    
    PHP:

    i just want select recode and delete it and redirect page to recode list page again just that i want. plz anyone can help me
     
    indika250, Feb 13, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    first, you can add all this code into one page

    second, use $_SERVER['REQUEST_METHOD'] == "POST" to find out if a form has been submitted

    third, instead of radio buttons, use checkboxes, then you can remove multiple at a time.

    fourth, if you have lots of work to do, let someone make some bucks and save the time! :)

    GL
     
    EricBruggema, Feb 14, 2012 IP
  3. idotcom

    idotcom Well-Known Member

    Messages:
    522
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #3
    and boy are you asking for injection.... at least do... $trackingno = mysql_real_escape_string($_POST['trackingno']); and if is INT all the time validate it as int.
     
    idotcom, Feb 15, 2012 IP