Jump to content

Recommended Posts

Can anyone help me out my problem...

 

When i click on delete link, it should confirm through confirm box and delete checked multiple rows...

 

This is my code...

$sql = " SELECT * FROM budget where NAME=\"$name\";

$rs = mysql_query($sql,$con);

if(mysql_num_rows($rs) == 0)

{

echo("<p class=\"no\">Sorry, NO Records Found..!</p>

<p class=\"no\">Pleasd try with another Name.</p>

");

}

else

{

echo "<table id='main-table' cellspacing='0' cellpadding='0' class=\"table1\">

<tr class=\"rowh\">

<td>Date</td>

<td>Name</td>

<td colspan=\"2\"> ACTIONS </td>

</tr>";

while ($row=mysql_fetch_array($rs))

{

echo ("<tr><td class=\"rowr\">$row[DATE]</td>");

echo ("<td class=\"rowr\">$row[NAME]</td>");

echo ("<td ><a class=\"rowrl\" href==\"edit_form.php?number=$row[iD]\"> Edit </a></td>");

echo ("<td ><input name=\"check\" type=\"checkbox\" /></td></tr>");

}

echo "<tr class=\"delete\" align=\"right\" >

<td colspan=\"7\" align=\"right\"><a class=\"rowrl\" href=\"delete.php?number=$row[iD]\" onclick=\"return confirm('Do you really want to DELETE ?');\"> Delete </a></td>

</tr>";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/282688-del/
Share on other sites

Your code as-s wont submit the checked values as <input />'s belong to forms not links.

 

What you need to do is surround the table with a form that submits to delete.php. Then set the onsubmit attribute to the confirm dialog box which pops up when the submit button is pressed.

 

 

<form action="delete.php" method="get" onsubmit="return confirm('Do you really want to DELETE ?');")>
 
   ... table code here ...
 
   <input type="submit" name="submit" value="Delete" />
</form>
Link to comment
https://forums.phpfreaks.com/topic/282688-del/#findComment-1452467
Share on other sites

In order for the values of the selected checkboxes to be received in delete.php you need to have a form. Once you have the form implemented you can submit the form using the anchor tag if you wish.

 

You'll set up the checkboxes with this

echo ("<td ><input name=\"del[]\" value=\"{$row['ID']}\" type=\"checkbox\" /></td></tr>");
 

Now in delete.php how you'd proceses the selected checkboxes would be like this

if(is_array($_GET['del']))
{
   $ids = array_map('intval', $_GET['del']);
   $ids = implode(',', $ids);
   $query = mysql_query("DELETE FROM your_table WHERE your_id_field IN ($ids)");
}
Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/282688-del/#findComment-1452473
Share on other sites

@ch0cu3r:

not done ch0cu3r....

 

i've closed if loop before sql query stmt.

Is that true ?

 

Its going to my delete.php and executing but showing updated records: -1 ..????

My code After query

if(isset($sql))

{echo"deletd sucfly";

printf("updated records:", mysql_affected_rows());

}

Link to comment
https://forums.phpfreaks.com/topic/282688-del/#findComment-1452592
Share on other sites

@igen121  :confused: how is that helping?
 
 
@Pradeep_Chinna

Post delete.php here. How are you implanting my code example? if mysql_affected_rows() returned -1 then the SQL query is failing, probably due to an error. You can see what the error is using mysql_error
 
When posting code, please paste code into the code tags by clicking the <>  button.

Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/282688-del/#findComment-1452594
Share on other sites

Sorry for late :-P

Am using mobile not computer. There is no other bb or color opts in mobile version.

 

@ch0cr3:

i've deletd unnecessary code.

this is my delete.php:

<body background="bg_tile.jpg">

<div class="content">

<div class="header"> <div class="uname">

<div class="welcome">

<?php

if(isset($_SESSION['username'])) {

echo "Welcome ".$_SESSION['username']."<br/>"."<br/>";?>

<?php echo "<br/>";

}

?>

</div>

<div class="logout">

<a class="logout2" href="index.php">Logout</a>

</div>

<span id="date_time"></span>

</div>

<div class="separator"></div>

</div>

<div class="right-div">

<?php

$no=$_GET['number'];

$checkbox= $_POST['checkbox'];

// Connect to the database

$con = mysql_connect("localhost","admin","");

// Make sure we connected succesfully

if(! $con)

{

die('Connection Failed'.mysql_error());

}

// Select the database to use

mysql_select_db("test",$con);

if(is_array($_GET['del']))

{

$ids = array_map('intval', $_GET['del']);

$ids = implode(',',$ids);

}

$order = " DELETE FROM budget WHERE ID IN($ids) ";

$result=mysql_query($order, $con);

if(isset($result))

{

print "Deleted successfully "; echo "<br/>";

printf ("Updated records: %d\n", mysql_affected_rows()); echo "<br/>"."<br/>";

}

?>

</div>

<div class="footer">

<div class="footer_inside" ><p class="text">©2013 All Rightst5a </p>

</div>

</div>

</div>

</body>

Link to comment
https://forums.phpfreaks.com/topic/282688-del/#findComment-1452663
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.