Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to execute mysql on button click
    primarykey
    data
    text
    <p>PHP:<br/> How would I execute SQL when a button is clicked? Would I do it with the JavaScript <code>onClick()</code> function, or some other way? I am trying to do this inside of a loop, and only execute the sql on the row that the button is clicked on... Thanks!</p> <p>Code for <strong>@PHPnoOb</strong> to help: Okay, so now I have all of that sorted out, but when the button is clicked it executes once for each row... not just once for the row the button was clicked on! I only want the row that the button was clicked on to be queried... my code:</p> <pre><code>while($row = mysqli_fetch_array($result)) { //FAULTY CODE!!! EXECUTES ONCE FOR EACH ROW! //I WANT IT TO ONLY EXECUTE FOR THE ROW THE //BUTTON WAS CLICKED ON if(isset($_POST['delete'])){ echo "You clicked on: ".$row['subject']; //eventually i will have sql query up here } //echo all the results into a table... messy echo" &lt;tr&gt;&lt;td&gt;&lt;div align='center'&gt;&lt;font color='grey'&gt;".$row['date']."&lt;/font&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align='center'&gt; ".$row['sender']."&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align='center'&gt; ".$row['subject']."&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align='center'&gt;&lt;input type='button' value='open' onClick='window.alert(\"On ".$row['date']." ".$row['sender']." wrote:\\n".$row['message']."\")'/&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align='center'&gt;&lt;form method='post'&gt;&lt;input type='submit' value='delete' name='delete'/&gt;&lt;/form&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; "; } echo '&lt;/table&gt;'; //ends the table. </code></pre>
    singulars
    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