Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate not working in mysql php
    text
    copied!<p>When I tried to update data, I got same data but no updating. I can't find where went wrong. Updating goes without any error shown, but no updating when I view the code. So updating is not working. When I tried to update data, I got same data but no updating. I can't find where went wrong. Updating goes without any error shown, but no updating when I view the code. So updating is not working.</p> <p> <pre><code>// Start the session session_start(); $dbc = mysqli_connect('localhost', 'root', '', 'onlinetest'); $sumid = $_SESSION['sumid']; if (!isset($_POST['submit'])) { $_SESSION['sumid'] = $_GET['sumid']; $query = "SELECT question, answer FROM sum WHERE sumkey = '$sumid' "; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $row = mysqli_fetch_array($data); $question = $row['question']; $answer = $row['answer']; echo $question . $sumid; } mysqli_close($dbc); } if (isset($_POST['submit'])) { //$Test = $_SESSION['testid']; $question1 = $_POST['question']; $answer1 = $_POST['answer']; $dbc = mysqli_connect('localhost', 'root', '', 'onlinetest'); // $dbc = mysqli_connect('localhost', 'root', '', 'onlinetest'); $query = "UPDATE sum SET question = $question1,answer = $answer1 WHERE sumkey = $sumid"; mysqli_query($dbc, $query); echo 'New test name added'; echo ''.$question1; mysqli_close($dbc); //exit(); } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt;Add sum&lt;/div&gt; &lt;form method="post" action ="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt; &lt;p&gt; &lt;label for="textarea"&gt;&lt;/label&gt; &lt;label&gt;Question&lt;/label&gt;&lt;/p&gt; &lt;p&gt; &lt;textarea name="question" id="question" value="" cols="100" rows="9"&gt;&lt;?php echo $question ?&gt;&lt;/textarea&gt; &lt;/p&gt; &lt;p&gt;&lt;label&gt;Answer&lt;/label&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt; &lt;label for="textarea2"&gt;&lt;/label&gt; &lt;textarea name="answer" cols="100" rows="20" id="answer" value=""&gt;&lt;?php echo $answer ?&gt;&lt;/textarea&gt; &lt;/p&gt; &lt;p&gt; &lt;input type ="submit" value="ADD" name="submit"/&gt; &lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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