Vinsanity Posted January 15, 2007 Share Posted January 15, 2007 Can anyone provide me the sources or codes for the delete function using the checkbox... it can be a very simple delete using checkbox since i m a newbie of php... I got these fields in my database(JobID, JobTitle, JobRequirement, Location, JobStatus and CompanyName) and i wan to delete the certain rows when i checked the row and click on the delete button... Can anybody help me... Any help will be appreciated... Quote Link to comment https://forums.phpfreaks.com/topic/34204-delete-rows-using-checkbox/ Share on other sites More sharing options...
scotmcc Posted January 15, 2007 Share Posted January 15, 2007 There are several topics posted about this already, you should search the forum...But, to get you started:create a checkbox, the value of this checkbox should be the rowid for the row which you want to delete. After checking the box click submit. After submitting the page, grab the list of posted variables and then execute a SQL query: DELETE FROM [table][tr][td] WHERE [ROWID] = $_POST['checkbox value'];Or something like that :)Scot Quote Link to comment https://forums.phpfreaks.com/topic/34204-delete-rows-using-checkbox/#findComment-160937 Share on other sites More sharing options...
Vinsanity Posted January 15, 2007 Author Share Posted January 15, 2007 [img]http://C:\Documents and Settings\L340C27\My Documents\My Pictures\error.bitmap[/img]<?php // connect and select the database $conn = mssql_connect($host, $user, $password) or die(mssql_error()); $db = mssql_select_db($dbName, $conn) or die(mssql_error()); $sql="SELECT * FROM Job";$result=mssql_query($sql);$count=mssql_num_rows($result);?><table width="400" border="0" cellspacing="1" cellpadding="0"><tr><td><form name="form1" method="post" action=""><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr><td bgcolor="#FFFFFF"> </td><td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mssql</strong> </td></tr><tr><td align="center" bgcolor="#FFFFFF">#</td><td align="center" bgcolor="#FFFFFF"><strong>JobID</strong></td><td align="center" bgcolor="#FFFFFF"><strong>JobTitle</strong></td><td align="center" bgcolor="#FFFFFF"><strong>Location</strong></td><td align="center" bgcolor="#FFFFFF"><strong>CompanyName</strong></td></tr><?phpwhile($rows=mssql_fetch_array($result)){?><tr><td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" value="<?php echo $rows['JobID']; ?>"></td><td bgcolor="#FFFFFF"><?php echo $rows['JobID']; ?></td><td bgcolor="#FFFFFF"><?php echo $rows['JobTitle']; ?></td><td bgcolor="#FFFFFF"><?php echo $rows['Location']; ?></td><td bgcolor="#FFFFFF"><?php echo $rows['CompanyName']; ?></td></tr><?php}?><tr><td colspan="5" align="center" bgcolor="#FFFFFF"><input type="submit" name="delete" value="Delete"></td></tr><?php//Check if delete button active, start this if(isset($_POST['delete'])){for($i=0;$i<$count;$i++){$del_id = $checkbox[$i];$sql = "DELETE FROM Job WHERE JobID='$del_id'";$result = mssql_query($sql);}if($result){//echo "<meta http-equiv=\"refresh\" content=\"0;URL=DeleteJ.php\">";}}mssql_close($conn);?></table></form></td></tr></table> Quote Link to comment https://forums.phpfreaks.com/topic/34204-delete-rows-using-checkbox/#findComment-160948 Share on other sites More sharing options...
Vinsanity Posted January 15, 2007 Author Share Posted January 15, 2007 the above code detected an error named 'undefined checkbox' and the checkbox mentioned is at the bottom of the code that [ $del_id = $checkbox[$i]; ]can anyone list out the solution for it... Quote Link to comment https://forums.phpfreaks.com/topic/34204-delete-rows-using-checkbox/#findComment-160956 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.