Delete multiple rows using checkbox + PHP coding

  • hidemoto1322
  • Born
  • Born
  • hidemoto1322
  • Posts: 1

Post 3+ Months Ago

Hi...i'm new in PHP...I need to create a form that can let user to delete the information that they dont want...My database name is call biodiversity and it consists of two tables that is plant and physicaldescription.Below is my coding for my page...but i dont know why when i run it at localhost it didnt show all the records in my database...and when click on the checkbox to delete my records, it wasnt deleted...i need help urgently!!!!thanks in advance!!!!

Code: [ Select ]
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';
$database = 'biodiversity';
$table = 'plant';

if (!mysql_connect($db_host, $db_user, $db_pwd)) 
    die("Can't connect to database");
if (!mysql_select_db($database)) 
    die("Can't select database");

$query="SELECT * FROM plant ORDER BY PlantId ASC"; //MySQL query
$numresults = mysql_query ($query) or die ( "Couldn't execute query" );
$row_linkcat= mysql_fetch_array ($numresults);
//results from query is displayed in the table below and later passed to page "delete.php"
?>

<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';
$database = 'biodiversity';
$table = 'plantdescription';

if (!mysql_connect($db_host, $db_user, $db_pwd)) 
    die("Can't connect to database");
if (!mysql_select_db($database)) 
    die("Can't select database");

$query="SELECT * FROM physicaldescription ORDER BY PlantId ASC"; //MySQL query
$numresults = mysql_query ($query) or die ( "Couldn't execute query" );
$row_linkcat= mysql_fetch_array ($numresults);
//results from query is displayed in the table below and later passed to page "delete.php"
?>

<p class="style1">Plant and Physical Description Record</p>
        <form name="delete record" method="post" action="delete.php">
        
        <table style="width: 100%">
            <tr>
                <td>&nbsp;</td>
                <td class="style2">Plant <br />ID</td>
                <td class="style2">Scientific <br />Name</td>
                <td class="style2">Common <br />Name</td>
                <td class="style2">Origin</td>
                <td class="style2">Image<br />ID</td>
                <td class="style2">Flower</td>
                <td class="style2">Leaf</td>
            </tr>
            <tr>
                <td class="style2"> <input type="checkbox" name="<?=$row_linkcat['genID']?>" id="<?=$row_linkcat['genID']?>" value="<?=$row_linkcat['genID']?>" /></td>
                <td class="style2"> <? echo $row_linkcat[ 'plantid' ]; ?></td>
                <td class="style2"> <? echo $row_linkcat[ 'scientificname' ]; ?></td>
                <td class="style2"> <? echo $row_linkcat[ 'commonname' ]; ?></td>
                <td class="style2"> <? echo $row_linkcat[ 'origin' ]; ?></td>
                <td class="style2"> <? echo $row_linkcat[ 'imageiD' ]; ?></td>
                <td class="style2"> <? echo $row_linkcat[ 'flower' ]; ?></td>
                <td class="style2"> <? echo $row_linkcat[ 'leaf' ]; ?></td>

            </tr>
        </table>
<?php
while ($row_linkcat= mysql_fetch_array ($numresults));
?>

<p>
        <input name="Submit1" type="submit" value="Delete Selected Record(s)" /></p>
        </form>
  1. <?php
  2. $db_host = 'localhost';
  3. $db_user = 'root';
  4. $db_pwd = '';
  5. $database = 'biodiversity';
  6. $table = 'plant';
  7. if (!mysql_connect($db_host, $db_user, $db_pwd)) 
  8.     die("Can't connect to database");
  9. if (!mysql_select_db($database)) 
  10.     die("Can't select database");
  11. $query="SELECT * FROM plant ORDER BY PlantId ASC"; //MySQL query
  12. $numresults = mysql_query ($query) or die ( "Couldn't execute query" );
  13. $row_linkcat= mysql_fetch_array ($numresults);
  14. //results from query is displayed in the table below and later passed to page "delete.php"
  15. ?>
  16. <?php
  17. $db_host = 'localhost';
  18. $db_user = 'root';
  19. $db_pwd = '';
  20. $database = 'biodiversity';
  21. $table = 'plantdescription';
  22. if (!mysql_connect($db_host, $db_user, $db_pwd)) 
  23.     die("Can't connect to database");
  24. if (!mysql_select_db($database)) 
  25.     die("Can't select database");
  26. $query="SELECT * FROM physicaldescription ORDER BY PlantId ASC"; //MySQL query
  27. $numresults = mysql_query ($query) or die ( "Couldn't execute query" );
  28. $row_linkcat= mysql_fetch_array ($numresults);
  29. //results from query is displayed in the table below and later passed to page "delete.php"
  30. ?>
  31. <p class="style1">Plant and Physical Description Record</p>
  32.         <form name="delete record" method="post" action="delete.php">
  33.         
  34.         <table style="width: 100%">
  35.             <tr>
  36.                 <td>&nbsp;</td>
  37.                 <td class="style2">Plant <br />ID</td>
  38.                 <td class="style2">Scientific <br />Name</td>
  39.                 <td class="style2">Common <br />Name</td>
  40.                 <td class="style2">Origin</td>
  41.                 <td class="style2">Image<br />ID</td>
  42.                 <td class="style2">Flower</td>
  43.                 <td class="style2">Leaf</td>
  44.             </tr>
  45.             <tr>
  46.                 <td class="style2"> <input type="checkbox" name="<?=$row_linkcat['genID']?>" id="<?=$row_linkcat['genID']?>" value="<?=$row_linkcat['genID']?>" /></td>
  47.                 <td class="style2"> <? echo $row_linkcat[ 'plantid' ]; ?></td>
  48.                 <td class="style2"> <? echo $row_linkcat[ 'scientificname' ]; ?></td>
  49.                 <td class="style2"> <? echo $row_linkcat[ 'commonname' ]; ?></td>
  50.                 <td class="style2"> <? echo $row_linkcat[ 'origin' ]; ?></td>
  51.                 <td class="style2"> <? echo $row_linkcat[ 'imageiD' ]; ?></td>
  52.                 <td class="style2"> <? echo $row_linkcat[ 'flower' ]; ?></td>
  53.                 <td class="style2"> <? echo $row_linkcat[ 'leaf' ]; ?></td>
  54.             </tr>
  55.         </table>
  56. <?php
  57. while ($row_linkcat= mysql_fetch_array ($numresults));
  58. ?>
  59. <p>
  60.         <input name="Submit1" type="submit" value="Delete Selected Record(s)" /></p>
  61.         </form>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 138 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.