473,388 Members | 1,207 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,388 software developers and data experts.

Make Check Button

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 1913
hsriat
1,654 Expert 1GB
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
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.php" 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 Expert 4TB
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("DELETE 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
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("DELETE 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 "successfully 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 Expert 1GB
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
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 Expert 1GB
Try this...[php]
<?
include("test.php");
mysql_select_db("a2840013_Database",$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 "Successfully deleted:<br/>".implode(",", array_diff($_POST[checkbox], $not_deleted));

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

?>
[/php]
Mar 23 '08 #8
Try this...[php]
<?
include("test.php");
mysql_select_db("a2840013_Database",$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 "Successfully deleted:<br/>".implode(",", array_diff($_POST[checkbox], $not_deleted));

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

?>
[/php]
i have write it like this...
[php]
<?
include("test.php");
mysql_select_db("a2840013_Database",$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 "Successfully deleted:<br/>".implode(",", array_diff($_POST[checkbox], $not_deleted));
if (count($not_deleted)>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_cust.php'>";
while($row=mysql_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='center'> $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'><h3> Jumlah Record Customer Tersimpan= $Te </h3></b></font>";
?>
[/php]
thank you for all your help...
Mar 23 '08 #9
hsriat
1,654 Expert 1GB
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
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.
thank you hsriat... that was really helpful. Very glad you help me... :)
now i know where my fault... have the answer now... :)
Mar 24 '08 #11
hsriat
1,654 Expert 1GB
thank you hsriat... that was really helpful. Very glad you help me... :)
now i know where my fault... have the answer now... :)
And what was the fault?
Mar 24 '08 #12
And what was the fault?
i was mistake with double quote... :)
the first i was dont know that one quote is as a string. now i know it ... .
:)
thank you hsriat.... one thing again...
can you explain me...
Expand|Select|Wrap|Line Numbers
  1.     foreach($_POST[checkbox] as $key=>$selected_id)
  2.  
what is $key=>$selected_id meaning?
can you give me a link that explain this?
thank you...for your help....
Mar 24 '08 #13
hsriat
1,654 Expert 1GB
You are welcome. :)

You may know about foreach here.
Mar 24 '08 #14

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

Similar topics

16
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,...
6
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...
5
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...
4
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.