473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Make Check Button

29 New Member
hi again... :)
please help me,how to make a check button,so the user can check which one to delete...and how to implement it with "delete" selected check button?
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3.     while($row=mysql_fetch_assoc($result)){
  4.     echo "<table width ='100%' border='1'>";
  5.         echo "
  6.         <tr>
  7.         <td width = '10%'> $row[id_Customer] </td>
  8.         <td width = '30%'> $row[Nama_Customer] </td>
  9.         <td width = '20%'> $row[Alamat] </td>
  10.         <td width = '10%'> $row[Kota] </td>
  11.         <td width = '20%'> $row[C_Person] </td>
  12.         <td width = '5%'align='center'> $row[Nom] </td>
  13.         </tr>
  14.         </table>";
  15.     }
  16.  
  17. $Te =mysql_num_rows($result);
  18. echo "<b><font color='blue'><h3> Record Number= $Te </h3></b></font>";
  19. mysql_close($cipai); 
  20.  
  21. ?>
  22.  
what code i must insert in my code,to have a check button each record... and how the procedure to check the "check button"?
if any link will answer this question,it will be help. thank you...
Mar 22 '08 #1
13 1930
hsriat
1,654 Recognized Expert Top Contributor
Include the line[php]"<td><input type=\"checkbox \" name=\"checkbox[]\" value=\"".$row[id_Customer]."\" ></input></td>"[/php] within the second echo of the while loop.

Start form tag before the while loop and end it after the while loop.

Make another PHP file (action of form tag in above code) to delete the selected id.[php]<?php
foreach($_POST[checkbox] as $key=>$selected _id)
{
//delete the $selected_id from db
}
?>[/php]
Mar 22 '08 #2
wireshark
29 New Member
thank for reply...
i have write this code with your suggest...
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3.     echo "<form method='POST' action='del_cust.php'>";
  4.     while($row=mysql_fetch_assoc($result)){
  5.     echo "<table width ='100%'+ border='1'>";
  6.  
  7.         echo "
  8.         <tr>
  9.         <td><input type='checkbox' name='checkbox[]' value=''.$row[id_Customer].''></td>
  10.         <td width = '10%'> $row[id_Customer] </td>
  11.         <td width = '30%'> $row[Nama_Customer] </td>
  12.         <td width = '20%'> $row[Alamat] </td>
  13.         <td width = '10%'> $row[Kota] </td>
  14.         <td width = '20%'> $row[C_Person] </td>
  15.         <td width = '5%'align='center'> $row[Nom] </td>
  16.         </tr>
  17.         </table>";
  18.     }
  19.     echo "<input type='submit' value='Submit' name='submit'>";
  20.     echo "</br><input type='text' name='nomdat'>";
  21.     echo"</form>";
  22. ?>
  23.  
and in "del_cust.p hp" i write my code like this...
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     include("test.php");
  3.     mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form");
  4.  
  5.     foreach($_POST[checkbox] as $key=>$selected_id){
  6.     print("$key");
  7.  }
  8.     mysql_query($sql_str); 
  9. ?>
  10.  
1. the result is...012 (the index of the check box). i just get the index of the check box. how do i implement to delete database with that index i got?
2. what if i want to get "Nom" field as a direction to delete in my query. "Nom" field is a Autonumber ?
thanks for the answer...
Mar 22 '08 #3
Markus
6,050 Recognized Expert Expert
I think, in your foreach loop, youre in need of a delete query. And you want Nom to be how you select the row?

(sorry for jumping in on this hsriat - im bored =/)

Try adding this (you might have to change the tbl_name - well, there's no 'might' about it... you will have to change it)
[php]
foreach($.... )
{
mysql_query("DE LETE FROM `tbl_name` WHERE `Nom` = '{$selected_id} '"
or die(mysql_error ());
echo "$selected_ id successfully deleted! <br /> \n";
}
[/php]

Hope this helps :)
Mar 22 '08 #4
wireshark
29 New Member
I think, in your foreach loop, youre in need of a delete query. And you want Nom to be how you select the row?

(sorry for jumping in on this hsriat - im bored =/)

Try adding this (you might have to change the tbl_name - well, there's no 'might' about it... you will have to change it)
[php]
foreach($.... )
{
mysql_query("DE LETE FROM `tbl_name` WHERE `Nom` = '{$selected_id} '"
or die(mysql_error ());
echo "$selected_ id successfully deleted! <br /> \n";
}
[/php]

Hope this helps :)
thanks for reply... but i dont still get it.. can u help me again? :)
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     include("test.php");
  3.     mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form");
  4.  
  5.     foreach($_POST[checkbox] as $key=>$selected_id)
  6.     {
  7.     mysql_query("DELETE FROM customer WHERE Nom = '{$selected_id}'") or die ("Cannot Delete");
  8.     echo "$selected_id successfully deleted! <br /> \n";
  9.     };
  10. ?>
  11.  
this is what i wrote down...the result is "successful ly deleted !" but it not delete anything.
can u show me again,what must i correct in my script? thank you...
Mar 22 '08 #5
hsriat
1,654 Recognized Expert Top Contributor
Run delete query with primary key.
If primary key is Nom, replace customer_id with Nom in id of checkbox, else replace Nom with customer_id.
Mar 22 '08 #6
wireshark
29 New Member
Run delete query with primary key.
If primary key is Nom, replace customer_id with Nom in id of checkbox, else replace Nom with customer_id.
thanks for reply,did you mean like this? still have the same result. my primary is id_Customer.
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     include("test.php");
  3.     mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form");
  4.  
  5.     foreach($_POST[checkbox] as $key=>$selected_id)
  6.     {
  7.     echo "$selected_id";
  8.     mysql_query("DELETE FROM customer WHERE id_Customer = '{$selected_id}'") or die ("Cannot Delete");
  9.  
  10.     echo "$selected_id successfully deleted! <br /> \n";
  11.     };
  12.  
  13. ?>
  14.  
Mar 23 '08 #7
hsriat
1,654 Recognized Expert Top Contributor
Try this...[php]
<?
include("test.p hp");
mysql_select_db ("a2840013_Data base",$cipai) or die ("Cannot Connect At Delete Form");

$not_deleted = array(); //TO SAVE DELETED IDS
foreach($_POST[checkbox] as $key=>$selected _id)
{

if (!mysql_query(" DELETE FROM `customer` WHERE `id_Customer` = '".$selected_id ."'"))
array_push($not _deleted, $selected_id);
}

echo "Successful ly deleted:<br/>".implode(", ", array_diff($_PO ST[checkbox], $not_deleted));

if (count($not_del eted)>0)
echo "<br/>Unable to delete:<br/>".implode(", ", $not_deleted);

?>
[/php]
Mar 23 '08 #8
wireshark
29 New Member
Try this...[php]
<?
include("test.p hp");
mysql_select_db ("a2840013_Data base",$cipai) or die ("Cannot Connect At Delete Form");

$not_deleted = array(); //TO SAVE DELETED IDS
foreach($_POST[checkbox] as $key=>$selected _id)
{

if (!mysql_query(" DELETE FROM `customer` WHERE `id_Customer` = '".$selected_id ."'"))
array_push($not _deleted, $selected_id);
}

echo "Successful ly deleted:<br/>".implode(", ", array_diff($_PO ST[checkbox], $not_deleted));

if (count($not_del eted)>0)
echo "<br/>Unable to delete:<br/>".implode(", ", $not_deleted);

?>
[/php]
i have write it like this...
[php]
<?
include("test.p hp");
mysql_select_db ("a2840013_Data base",$cipai) or die ("Cannot Connect At Delete Form");
$not_deleted = array();
foreach($_POST[checkbox] as $key=>$selected _id)
{
if (!mysql_query(" DELETE FROM customer WHERE id_Customer = '".$selected_id ."'"))
array_push($not _deleted, $selected_id);
}
echo "Successful ly deleted:<br/>".implode(", ", array_diff($_PO ST[checkbox], $not_deleted));
if (count($not_del eted)>0)
echo "<br/>Unable to delete:<br/>".implode(", ", $not_deleted);
?>
[/php]
but the result is... Successfully deleted: and with "," in the new line...
if i try delete 3 record then ",," just like that...or maybe in my delete.php something wrong? this is the code
[php]
<?

echo "<form method='POST' action='del_cus t.php'>";
while($row=mysq l_fetch_assoc($ result)){
echo "<table width ='100%'+ border='1'>";
echo "
<tr>
<td><input type='checkbox' name='checkbox[]' value=''.$row[id_Customer].''></input></td>
<td width = '10%'> $row[id_Customer] </td>
<td width = '30%'> $row[Nama_Customer] </td>
<td width = '20%'> $row[Alamat] </td>
<td width = '10%'> $row[Kota] </td>
<td width = '20%'> $row[C_Person] </td>
<td width = '5%'align='cent er'> $row[Nom] </td>
</tr>
</table>";
}
echo "<input type='submit' value='Submit' name='submit'>" ;
echo "</br><input type='text' name='nomdat'>" ;
echo"</form>";
$Te =mysql_num_rows ($result);

echo "<b><font color='blue'><h 3> Jumlah Record Customer Tersimpan= $Te </h3></b></font>";
?>
[/php]
thank you for all your help...
Mar 23 '08 #9
hsriat
1,654 Recognized Expert Top Contributor
You have a syntax mistake. Use double quotes instead of single.
Use this..
Expand|Select|Wrap|Line Numbers
  1. <td><input type=\"checkbox\" name=\"checkbox[]\" value=\"".$row[id_Customer]."\"  ></input></td>
or use this..
Expand|Select|Wrap|Line Numbers
  1. <td><input type='checkbox' name='checkbox[]' value='".$row[id_Customer]."'  ></input></td>
If a string starts with double quote, it ends with double quote only. Single quote is then just treated as a part of the string, but not an operator.
Mar 23 '08 #10

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

Similar topics

16
11540
by: Miguel Dias Moura | last post by:
Hello, i have 5 panels in an ASP.net / VB page. The panel 1 is visible the other 4 are NOT visible. I also have 5 images: image 1, image 2, ..., image5. When i click one of the images, image N, the panel N becomes visible and all the other invisible.
6
4866
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
5
4171
by: itfetish | last post by:
I have made an electronic sign out book for my office in ASP using VBScript. Problem is, when there is a fire we need to check who is out and who is burning. I have been trying to think of how to go about this, perhaps the only way is by having an 'emergency print' button that quickly prints thedocument to one, or even better all printers on the network. That way when everyone is leaving they can grab the print from the printer.
4
1750
by: LoveLorn | last post by:
how can i make my node info in linked list as an object of another class f.e i want to make my node data as a person information like name , surname , date of birth and job . can any one help me plz
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.