当我尝试更新数据时,我得到了相同的数据但没有更新。我找不到哪里出错了。更新没有显示任何错误,但是当我查看代码时没有更新。所以更新不起作用。当我尝试更新数据时,我得到了相同的数据但没有更新。我找不到哪里出错了。更新没有显示任何错误,但是当我查看代码时没有更新。所以更新不起作用。
// 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();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div>Add sum</div>
<form method="post" action ="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>
<label for="textarea"></label>
<label>Question</label></p>
<p>
<textarea name="question" id="question" value="" cols="100" rows="9"><?php echo $question ?></textarea>
</p>
<p><label>Answer</label> </p>
<p>
<label for="textarea2"></label>
<textarea name="answer" cols="100" rows="20" id="answer" value=""><?php echo $answer ?></textarea>
</p>
<p>
<input type ="submit" value="ADD" name="submit"/>
</p>
</form>
</body>
</html>