Gazz1982 Posted June 6, 2008 Share Posted June 6, 2008 This displays my table: echo "<table border='1'> <tr> <th>Delete</th> <th>Firstname</th> <th>Lastname</th> <th>Email</th> <th>Password</th> <th>Company</th> <th>Address1</th> <th>Address2</th> <th>Address3</th> <th>County</th> <th>Country</th> <th>Post Code</th> <th>Phone Number</th> <th>Validate</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><form class='small'>'"; echo "<input type='checkbox' name='Delete' value='Delete' /></p></td>"; echo "<td>" . $row['NAME_FIRST'] . "</td>"; echo "<td>" . $row['NAME_LAST'] . "</td>"; echo "<td>" . $row['EMAIL'] . "</td>"; echo "<td>" . $row['PASSWORD'] . "</td>"; echo "<td>" . $row['COMPANY'] . "</td>"; echo "<td>" . $row['ADDRESS1'] . "</td>"; echo "<td>" . $row['ADDRESS2'] . "</td>"; echo "<td>" . $row['ADDRESS3'] . "</td>"; echo "<td>" . $row['COUNTY'] . "</td>"; echo "<td>" . $row['COUNTRY'] . "</td>"; echo "<td>" . $row['POST_CODE'] . "</td>"; echo "<td>" . $row['PHONE'] . "</td>"; echo "<td>" . $row['VALIDATE'] . "</td>"; echo "</tr>"; echo "<input type='submit' name='Delete' value='Delete' target='delete.php?'/></p>"; } echo "</table>"; I have a check box titled delete once this is checked I want to pass everything from that row to delete.php where the whole row is delete. I have a column in the database called delete so I assume that I need to insert into login where (checkbox is ticked == true) using some kind of if statement - if checkbox ticked == true insert 'yes' into delete then delete * from login where delete ='yes' How do I do this? see www.noblesweb.co.uk/manager.php Thanks Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 6, 2008 Share Posted June 6, 2008 Instead of having a field named "delete" in the database, use a uniqueID field. Do you have one that holds an auto-incremented ID? If you do, thats the field you should be using. I put comments in the code <?php if (isset($_POST['delete_fields'])){ //delete all checked rows $query = "DELETE FROM table_name WHERE id IN(".implode(",", $_POST['delete']).")"; $result = mysql_query($query)or die(mysql_error()."<p>With query:<br>$query"); echo "Rows Deleted<p>"; } echo "<table border='1'> <tr> <th>Delete</th> <th>Firstname</th> <th>Lastname</th> <th>Email</th> <th>Password</th> <th>Company</th> <th>Address1</th> <th>Address2</th> <th>Address3</th> <th>County</th> <th>Country</th> <th>Post Code</th> <th>Phone Number</th> <th>Validate</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><form class='small'>'"; //You need to change the name to be an array, and the value should be your unique field. echo "<input type='checkbox' name='delete[]' value='{$row['UNIQUE_FIELD']}' /></p></td>"; echo "<td>" . $row['NAME_FIRST'] . "</td>"; echo "<td>" . $row['NAME_LAST'] . "</td>"; echo "<td>" . $row['EMAIL'] . "</td>"; echo "<td>" . $row['PASSWORD'] . "</td>"; echo "<td>" . $row['COMPANY'] . "</td>"; echo "<td>" . $row['ADDRESS1'] . "</td>"; echo "<td>" . $row['ADDRESS2'] . "</td>"; echo "<td>" . $row['ADDRESS3'] . "</td>"; echo "<td>" . $row['COUNTY'] . "</td>"; echo "<td>" . $row['COUNTRY'] . "</td>"; echo "<td>" . $row['POST_CODE'] . "</td>"; echo "<td>" . $row['PHONE'] . "</td>"; echo "<td>" . $row['VALIDATE'] . "</td>"; echo "</tr>"; echo "<input type='submit' name='delete_fields' value='Delete' target='delete.php?'/></p>"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted June 6, 2008 Share Posted June 6, 2008 Hi, can you please tell me what name i have to put as an array? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 7, 2008 Share Posted June 7, 2008 I put it in the code already, look for the comments (in yellow) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.