Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve a specific value from MySQL (PHP)
    primarykey
    data
    text
    <p>I am new to PHP and I would like some inputs on this little script. Everything seems to work but I need to know how to retrieve the "id" of the message that is modified.</p> <pre><code>&lt;?php function updatemyinfos() { $con=mysqli_connect("localhost","root","root","dbname"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } **$id=** $sql="UPDATE table1 SET message = '$_POST[message]' WHERE id ='$id'"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo '&lt;p&gt;Message modifié&lt;/p&gt;'; mysqli_close($con); } if(isset($_POST['updatemessage'])) { updatemyinfos(); } ?&gt; &lt;form action="#" method="post"&gt; &lt;textarea style="resize:none" cols="1" rows="1" name="message"id="textbox"&gt;'.$row['message'].'&lt;/textarea&gt; &lt;input type="submit" value="Soumettre" name="updatemessage" id="updatemessage"&gt; &lt;/form&gt; </code></pre> <p>EDIT : I tried this.. I don't get any error message but the datebase does not update. But I get the "echo '<p>Message modifié</p>"</p> <pre><code>&lt;?php function updatemyinfos($id) { $con=mysqli_connect("localhost","root","root","TP1AlexandreBouletCouture"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="UPDATE table1 SET message = '$_POST[message]' WHERE id ='$id'"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo '&lt;p&gt;Message modifié&lt;/p&gt;'; mysqli_close($con); } if(isset($_POST['updatemessage'])) { updatemyinfos($_POST['updatemessage']); } ?&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.
    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