473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Delete records via checkbox

I'm just learning PHP (extreme novice) and I'm struggling with deleting records using a checkbox included within each row.

I have a few idea but I'm not sure if my thoughts are correct. I think I need to turn it into a Form to be able to capture whats been checked but I would appreciate any guidance.

Most of the code I am using is from a solution a co-worker wrote for another solution and I learning by using it as a guide/example if some of it look advanced for an extreme novice.

Thanks in advance.

-------------------- Code showing to show the list ---------------------------

<?php
include_once('dAud_connect.php');
$dbh=mysql_connect($host,$user,$pass);
if (!$dbh)
{
echo "could not connect to database";
exit;
}
mysql_select_db($db);


{
$query = "select firstName, middleName, lastName, address1, address2, city, state, zip_code, country, phone, email, gender, citizenship, program, DATE_FORMAT(submitDate, '%m/%d/%Y') as submitDate, DATE_FORMAT(auditionDate, '%m/%d/%Y') as auditionDate from d_Aud";
}

$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if ($result)
{
echo "<table border=1>";
echo "<tr><th>firstName</th><th>middleName</th><th>lastName</th><th>Address1</th><th>Address2</th><th>city</th><th>state</th><th>zip</th><th>Country</th><th>phne</th><th>Email</th><th>Gender</th><th>Citizenship</th><th>Program</th><th>Audition Date</th><th>DateSubmitted</th><th>Delete</th></tr>";
while ($get_info = mysql_fetch_array($result))
{
echo "<tr>\n";
echo "\t<td>".stripslashes($get_info['firstName'])."</td>";
echo "\t<td>".stripslashes($get_info['middleName'])."</td>";
echo "\t<td>".stripslashes($get_info['lastName'])."</td>";
echo "\t<td>".stripslashes($get_info['address1'])."</td>";
echo "\t<td>".stripslashes($get_info['address2'])."</td>";
echo "\t<td>".stripslashes($get_info['city'])."</td>";
echo "\t<td>".stripslashes($get_info['state'])."</td>";
echo "\t<td>".stripslashes($get_info['zip_code'])."</td>";
echo "\t<td>".stripslashes($get_info['country'])."</td>";
echo "\t<td>".stripslashes($get_info['phone'])."</td>";
echo "\t<td>".stripslashes($get_info['email'])."</td>";
echo "\t<td>".stripslashes($get_info['gender'])."</td>";
echo "\t<td>".stripslashes($get_info['citizenship'])."</td>";
echo "\t<td>".stripslashes($get_info['program'])."</td>";
echo "\t<td>".stripslashes($get_info['auditionDate'])."</td>";
echo "\t<td>".stripslashes($get_info['submitDate'])."</td>";
echo "\t<td><input type='checkbox' name='del_me[]' value=\"$url\"></td>";
echo "</tr>\n";
}
echo "</table>";
}
echo mysql_error();
echo "<br />".$num_rows." records";
echo "<br /><a href='../php_inc/dAud_excel.php'>get as excel file</a>";
echo "<br /><a href='../php_inc/delete_entry.php'>delete check</a>";
?>



------------------ Code to Delete Rows ----------------------------

<?php
include_once('../php_inc/dAud_connect.php');
$dbh=mysql_connect($host,$user,$pass);
if (!$dbh)
{
echo "could not connect to database";
exit;
}

mysql_select_db($db);

$del_me = $HTTP_POST_VARS['del_me'];
$valid_user = $HTTP_SESSION_VARS['valid_user'];



if (count($del_me) >0)
{
foreach($del_me as $url)
{
if (delete_bm($valid_user, $url))
echo 'Deleted '.htmlspecialchars($url).'.<br />';
else
echo 'Could not delete '.htmlspecialchars($url).'.<br />';
}
}

?>
Oct 18 '06 #1
1 3959
Well i am a little confused by :
Expand|Select|Wrap|Line Numbers
  1. echo "\t<td><input type='checkbox' name='del_me[]' value=\"$url\"></td>";
What is the deal with the bracket -> del_me[]
And \"$url\" Should be something like $get_info['userID']

Or whatever as long as "userID" is a unique identifier to the row which shall be deleted.
When the user checks the button - do you envision the row deleting right then, the page refreshing and that row being gone????
If so, you will need to look into using something like attaching
Expand|Select|Wrap|Line Numbers
  1. onChange="submit()"
to each checkbox input....submit() being a javascript function that you created in the document header, that does at least:
Expand|Select|Wrap|Line Numbers
  1. function submit(){
  2. document.form.submit;}
Finally the hypothetical 'userID' will serve as the clause for a WHERE parameter in your delete statement....

Hope this helps!
Oct 18 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: neoconwannabe | last post by:
Hi, I have an html form with a number of checkboxes that can be checked to delete items. I want to have a javascript alert prompt box to pop up to confirm the delete. I am building my site with...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
3
by: Charleees | last post by:
Hi all, I have a DataGrid With Template Columns.. In the First Column i have a Check Box... Also i have a Button Outside the DataGrid..Just Above it.. What i want to do is .... I have to...
2
by: Birderman | last post by:
Hi, Using MS ACCESS 2003, i have a form for entering data. wih one object on the form (yes/no field) I want to inititiate vba code to run if it changes. I have no problem gettting it to update...
7
by: mukeshrasm | last post by:
hello everyone I want to delete the selected records from database using checkbox. whch is generated dyanamically and checkbox is also generated dynamically,using php. so please help me. if you...
0
by: sana krishna | last post by:
when I click the delete button ,display an error. object reference not set to an instance of an object.. My code.. I use ASP.NET 2.0 (C#) and oracle public void DeleteStore(Object sender,...
1
by: chocciies | last post by:
Hi! I want to delete multiple record via checkboxes. However, with no success. Is there sthg wrong with the value of my checkbox? Your help will be greatly appreciated. Thanks! <form...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
1
by: ahilar12 | last post by:
Hi all, I am new to php,my question is that in this following code i am retrieving many rows from the database which is working good.i want to delete a particular row(s) which is checked(checkbox)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.