Make Check Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • hsriat
    replied
    You are welcome. :)

    You may know about foreach here.

    Leave a comment:


  • wireshark
    replied
    Originally posted by hsriat
    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...
    Code:
        foreach($_POST[checkbox] as $key=>$selected_id)
    what is $key=>$selected _id meaning?
    can you give me a link that explain this?
    thank you...for your help....

    Leave a comment:


  • hsriat
    replied
    Originally posted by wireshark
    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?

    Leave a comment:


  • wireshark
    replied
    Originally posted by hsriat
    You have a syntax mistake. Use double quotes instead of single.
    Use this..
    Code:
    <td><input type=\"checkbox\" name=\"checkbox[]\" value=\"".$row[id_Customer]."\"  ></input></td>
    or use this..
    Code:
    <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... :)

    Leave a comment:


  • hsriat
    replied
    You have a syntax mistake. Use double quotes instead of single.
    Use this..
    Code:
    <td><input type=\"checkbox\" name=\"checkbox[]\" value=\"".$row[id_Customer]."\"  ></input></td>
    or use this..
    Code:
    <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.

    Leave a comment:


  • wireshark
    replied
    Originally posted by hsriat
    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...

    Leave a comment:


  • hsriat
    replied
    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]

    Leave a comment:


  • wireshark
    replied
    Originally posted by hsriat
    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.
    Code:
    <?
    	include("test.php");
    	mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form");
    	
    	foreach($_POST[checkbox] as $key=>$selected_id)
    	{
    	echo "$selected_id";
    	mysql_query("DELETE FROM customer WHERE id_Customer = '{$selected_id}'") or die ("Cannot Delete");
    	
    	echo "$selected_id successfully deleted! <br /> \n";
    	};
    	
    ?>

    Leave a comment:


  • hsriat
    replied
    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.

    Leave a comment:


  • wireshark
    replied
    Originally posted by markusn00b
    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? :)
    Code:
    <?
    	include("test.php");
    	mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form");
    	
    	foreach($_POST[checkbox] as $key=>$selected_id)
    	{
    	mysql_query("DELETE FROM customer WHERE Nom = '{$selected_id}'") or die ("Cannot Delete");
    	echo "$selected_id successfully deleted! <br /> \n";
    	};
    ?>
    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...

    Leave a comment:


  • Markus
    replied
    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 :)

    Leave a comment:


  • wireshark
    replied
    thank for reply...
    i have write this code with your suggest...
    Code:
    <?
    	
    	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].''></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>";
    ?>
    and in "del_cust.p hp" i write my code like this...
    Code:
    <?
    	include("test.php");
    	mysql_select_db("a2840013_Database",$cipai) or die ("Cannot Connect At Delete Form");
    	
    	foreach($_POST[checkbox] as $key=>$selected_id){
    	print("$key");
     }
    	mysql_query($sql_str); 
    ?>
    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...

    Leave a comment:


  • hsriat
    replied
    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]

    Leave a comment:


  • wireshark
    started a topic Make Check Button

    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?
    Code:
    <?
    	
    	while($row=mysql_fetch_assoc($result)){
    	echo "<table width ='100%' border='1'>";
    		echo "
    		<tr>
    		<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>";
    	}
    
    $Te =mysql_num_rows($result);
    echo "<b><font color='blue'><h3> Record Number= $Te </h3></b></font>";
    mysql_close($cipai); 
    
    ?>
    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...
Working...