Note that there are some explanatory texts on larger screens.

plurals
  1. PODeleting row from a MySQL Table using checkboxes and a button
    primarykey
    data
    text
    <p>I want to make a table with the members of a website and in this table when you check the checkboxes and you press the "Delete" button to delete this member from the members table and also to delete his applications from the applications table. With my code when I click the delete button it prints me "Query failed"</p> <p>This is my code:</p> <pre><code>&lt;?php require_once('config.php'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $data = mysql_query("SELECT * FROM members ") or die(mysql_error()); echo ' &lt;form action="members-exec.php"&gt; &lt;table width="760" border=1&gt; &lt;tr&gt;'; if(isset($_SESSION['SESS_RANK'])) { echo ' &lt;th&gt;&lt;/th&gt;'; } echo ' &lt;th&gt;Служител:&lt;/th&gt; &lt;th&gt;Отпуск отпреди 2009год.&lt;/th&gt; &lt;th&gt;Отпуск от мин. год.&lt;/th&gt; &lt;th&gt;Отпуск от тек. год.&lt;/th&gt; &lt;/tr&gt;'; while($info = mysql_fetch_array( $data )) { echo ' &lt;tr&gt;'; if(isset($_SESSION['SESS_RANK'])) { echo ' &lt;td&gt; &lt;input type="checkbox" name="'.$info['firstname'] .' '.$info['lastname'] .'" value="'.$info['firstname'] .' '.$info['lastname'] .'" /&gt; &lt;/td&gt;'; } echo ' &lt;td&gt;'.$info['firstname'] .' '.$info['lastname'] .'&lt;/td&gt; &lt;td&gt;'.$info['predi'] .'&lt;/td&gt; &lt;td&gt;'.$info['minali'] .'&lt;/td&gt; &lt;td&gt;'.$info['tekushti'] .'&lt;/td&gt;'; } echo' &lt;/tr&gt; '; echo '&lt;/table&gt;'; if(isset($_SESSION['SESS_RANK'])) { echo ' &lt;br&gt; &lt;input type="submit" name="remove" value="Delete" /&gt;&lt;/form&gt;'; } ?&gt; </code></pre> <p>This is my php part:</p> <pre><code> &lt;?php session_start(); require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $qry = "DELETE FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'" &amp;&amp; "DELETE FROM applications WHERE userfname = '$userfname'"; $result = mysql_query($qry); if($result) { header("location: members.php"); exit(); }else { die("Query failed"); } ?&gt; </code></pre> <p>EDIT:</p> <pre><code>&lt;?php session_start(); require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $qry = "DELETE FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'" ; $result = mysql_query($qry); $qry = "DELETE FROM applications WHERE userfname = '$userfname'"; $result = mysql_query($qry); if($result) { header("location: members.php"); exit(); }else { die("Query failed"); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload