Note that there are some explanatory texts on larger screens.

plurals
  1. POSet a forms element based on record updating in mysql
    primarykey
    data
    text
    <p>I have a PHP script that loads the users records that are in the MYSQL Database Table. </p> <p>This database table contains others reviews from the site as it is simply a reviews table. </p> <p>Each review or entry receives it's very own Unique ID. </p> <p>Once the user has loaded his/her reviews. I have a button on the table on the loaded page that allows them to update that specific record. </p> <p>Somehow I am needing to be able to pass the Unique ID from the mysql database (maybe through the button?) and place that into a hidden field on the form. </p> <p>The form will then submit when the user clicks submit and update the record that is associated with that unique id and no other records.</p> <p>I have tried for hours on end trying to figure out a logical solution to this problem with no success (obviously). I hope that this is specific enough on what I am needing and any help/suggestions will be appreciated! Thank you! </p> <p>Here is my code: </p> <p><strong>This is the php script that loads the reviews on the page.</strong></p> <pre><code>&lt;?php $con=mysqli_connect(""); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM comments WHERE email='$_SESSION[email]' ORDER BY dt"); echo "&lt;table cellpadding='5' cellspacing='5' border='1' width='auto'&gt; &lt;tr&gt; &lt;td colspan='5' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center;'&gt;The Green Panda&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center; vertical-align:center; background-color: #96b759; color: white;'&gt;Date&lt;/td&gt; &lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center; vertical-align:center; background-color: #96b759; color: white;'&gt;Email&lt;/td&gt; &lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center; vertical-align:center; background-color: #96b759; color: white;'&gt;Review&lt;/td&gt; &lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center; vertical-align:center; background-color: #96b759; color: white;'&gt;Update&lt;/td&gt; &lt;/tr&gt;"; while($row = mysqli_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center; vertical-align:center; background-color: #758F45; color: white;'&gt;" . $row['dt'] . "&lt;/td&gt;"; echo "&lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center; vertical-align:center; background-color: #758F45; color: white;'&gt;" . $row['email'] . "&lt;/td&gt;"; echo "&lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; border:1px solid black; text-align:center; vertical-align:center; background-color: #758F45; color: white;'&gt;" . $row['body'] . "&lt;/td&gt;"; echo "&lt;td colspan='2' style='padding-right:15px; padding-bottom:5px; padding-left: 10px; border:1px solid black; text-align:center; vertical-align:center; background-color: #758F45; color: white;'&gt;&lt;input type='button' value='Update' onclick='showDiv()'/&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; ?&gt; </code></pre> <p><strong>This the the html form</strong> </p> <pre><code>&lt;div id="update-form"&gt; &lt;form method="post" action="update.php"&gt; &lt;label&gt;Your Review:&lt;/label&gt; &lt;input type="text" name="body"&gt; &lt;input type="text" name="id" value="" readonly&gt; &lt;input type="submit" value="submit" onclick="hideDiv()"&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p><strong>This is the PHP script that processes the update (external script)</strong> </p> <pre><code>&lt;?php $con=mysqli_connect(""); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"UPDATE comments SET body= '$_POST[body]' WHERE id='$_POST[id]'"); mysqli_close($con); header("location:myReviews.php"); ?&gt; </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.
    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