Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to delete the database(mySQL) record in PHP, where did i go wrong?
    primarykey
    data
    text
    <p>I am trying to delete the records from the users table in mysql,</p> <p>the code goes like this.</p> <pre><code>if(isset($_GET['id'])) { //create query to delete the record $query = "DELETE FROM users WHERE id =" . int($_GET['id']) or die(mysql_error()); //execute query if($mysqli-&gt;query($query)) { //print number of affected rows echo $mysqli-&gt;affected_rows. " row(s) affected"; } else { //print error message echo "Error in query : $query " . $mysqli-&gt;error; } } else { echo "Could not Execute the Delete query"; } </code></pre> <p>at the same time i am iterating the records from the users table in the database and it goes like this.</p> <pre><code>//query to get records $query = "SELECT * FROM users"; //execute query if($result = $mysqli-&gt;query($query)) { // see if any rows were returned if($result-&gt;num_rows &gt; 0) { // if yes then print one after another echo "&lt;table cellpadding=10 border=1&gt;"; while($row = $result-&gt;fetch_array()) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" .$row[0] . "&lt;/td&gt;"; echo "&lt;td&gt;" .$row[1] . "&lt;/td&gt;"; echo "&lt;td&gt;" .$row[2] . "&lt;/td&gt;"; echo "&lt;td&gt;&lt;a href =" . $_SERVER['PHP_SELF']. "?id" .$row[0]. "&gt;Delete&lt;/a&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; } $result-&gt;close(); } </code></pre> <p>the problem is, i am able to get the records from the database and display it in the browser but when i try to delete the record the first condition does not pass i.e if(isset($_GET['id'])) instead it goes to else condition and print the message "Could not Execute the Delete query " , i guess it is not able to fetch the $_GET['id'] so only it refuses to enter the if condition, </p> <p>P.S :i would appreciate if someone explains me in simple words, i am a newbie to programming, thanks..</p>
    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.
    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