Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As per your given script, first you are fetching record then updating data so may be due to that its not showing you updated record. Just reverse the condition means put update if condition above the fetching query. Then first it will update the record and then fetch the updated record.</p> <p>Script are vulnerable for SQL injection, to prevent use <strong>mysqli_real_escape_string ()</strong> method. </p> <pre><code>// Start the session session_start(); $sumid = $_SESSION['sumid']; 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(); } $dbc = mysqli_connect('localhost', 'root', '', 'onlinetest'); 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); } ?&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>
    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.
    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