Jump to content

garvit184

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

garvit184's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ohk...Thanks a ton ! Got it and its working perfectly. Now, If I want to use a CSS button for deletion then how can I get my form to submit ? More precisely an Image as a delete button ?
  2. Thanks, now I get it ! I have one small problem in header location what should I put because I have user ajax to show that table in <div id="center"> now when I press delete it brings me to the main page and not " javascript:ajaxpage('inbox.php','center')" ? What I basically want is that in my inbox.php I have the table with all messages and when user selected the message he wants to delete and click delete he should redirected to the same inbox.php with the messages deleted from the table. The code you provided is working perfectly without ajax but with it I have problem in identifying what should I give in header location ?
  3. Thanx a lott Drummin & viviosoft. My code is perfectly working now !!! The code that Drummin provided works perfectly
  4. I tried using javascript method here is the code what I tried and I have also included the result I am get. The table is not getting populated neither the record is been deleted don't know why? I am new to PHP and can't the error. Here is the code please let me know if you can find the error or else explain me the method that I should use.. <?php $host = 'localhost'; // Host name $username = 'root'; // Mysql username $password = ''; // Mysql password $db_name = 'imail'; // Database name $tbl_name = 'messages'; // Table name - DO NOT TOUCH // Connect to server and select databse. mysql_connect($host, $username, $password) or die('cannot connect'); mysql_select_db($db_name) or die('cannot select DB'); $sql = 'SELECT * FROM `'.$tbl_name.'`'; $result = mysql_query($sql); ?> <script type="text/javascript"> function selectAll(x) { for(var i=0,l=x.form.length; i<l; i++) if(x.form.type == 'checkbox' && x.form.name != 'sAll') x.form.checked=x.form.checked?false:true } </script> <table width="653" border="0" cellspacing="1" cellpadding="0"> <tr> <td width="651"> <form name="form1" method="post" action=""> <table width="694" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="57" bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td width="57" align="center" bgcolor="#FFFFFF"><strong>MsgId</strong></td> <td width="176" align="center" bgcolor="#FFFFFF"><strong>Username</strong></td> <td width="216" align="center" bgcolor="#FFFFFF"><strong>Message</strong></td> <td width="152" align="center" bgcolor="#FFFFFF"><strong>Subject</strong></td> </tr> <?php while ($rows = mysql_fetch_array($result)): ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="need_delete[<? echo $rows['msgid']; ?>]" type="checkbox" id="checkbox[<? echo $rows['msgid']; ?>]" value="<? echo $rows['msgid']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['msgid']; ?></td> <td bgcolor="#FFFFFF"><? echo htmlspecialchars($rows['username']); ?></td> <td bgcolor="#FFFFFF"><? echo htmlspecialchars($rows['message']); ?></td> <td bgcolor="#FFFFFF"><? echo htmlspecialchars($rows['subject']); ?></td> </tr> <?php endwhile; ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"> <input type="checkbox" name="sAll" onclick="selectAll(this)" /> (Select all)<br /> </td> </tr> <?php // Check if delete button active, start this if ( ! empty($_POST['delete'])) { foreach ($_POST['need_delete'] as $id => $value) { $sql = 'DELETE FROM `'.$tbl_name.'` WHERE `msgid`='.(int)$id; mysql_query($sql); } header('Location: shoutcron.php'); exit(); } mysql_close(); ?> </table> </form> </td> </tr> </table>
  5. Please can someone tell me how to use html form and php to delete selected values from database. here is my code :- while($row1 = mysql_fetch_array($result1)) { echo '<tr onmouseover="this.style.backgroundColor=… onmouseout="this.style.backgroundColor="… echo "<td>"; echo '<input type="checkbox" name="selected"/>'; echo "<td>" . $row1['username'] . "</td>"; echo "<td>" . $row1['subject'] . "</td>"; echo "<td>" . $row1['message'] . "</td>"; echo "</tr>"; } What I want is that user select the entries that he want to delete using checkbox I have given then he clicks at delete button which deletes the entries from the database using their ID's ? Please help its urgent I have to submit my project by Monday !
×
×
  • 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.