编辑值在php中无法正常工作

时间:2014-02-15 06:09:18

标签: php mysql edit

我创建了一个页面,其中检查和描述的数据从数据库显示到网页(页面名称为manageexam.php)

代码如下:  的 manageexam.php

<!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>Admin | Manage Exam</title>
<link rel="stylesheet" type="text/css" href="style1.css">
<style>
.active3{
    color:#900;
}
</style>
</head>

<body>
<?php include"livetime.php";?>
<table class="table">
<tr>
<th class="th" align="left" colspan="2" >
<?php
session_start();
if($_SESSION['username'])
echo "<span id='welcome'>Congratulation, <span id='company'> ".$_SESSION['username']."</span> you are logged in!</span>";
else
die("You Must be logged in!");
?>
<span class="clock"><span id="clockbox"></span></span></th>
</tr>
<tr>
<td valign="top" class="tdleft"><br>
<span class="message">Admin Controller</span>
<?php include('menu.php');?>
</td>

<td bgcolor="#FFFFCC" valign="top" style="padding:5px;">
<h2>Manage Exams Available:</h2>

<?php 
include('dbconfig.php');
$query = mysql_query("SELECT * FROM examsmeta");
$numrows = mysql_num_rows($query);
echo "<strong>Total Exams Available: $numrows </strong>";
echo "<br>";
echo "<table class='table2'>
<tr>
<th width='30%'>Subject Name</th>
<th width='60%'>Description</th>
<th width='30%'>Select</th>
</tr>
<form action= 'manageexam.php' method='post'>";
while($row = mysql_fetch_array($query))
{
    echo "<tr>";
    echo "<td>" .$row[1]. "</td>";
    echo "<td>" .$row[2]. "</td>";
    echo "<td><input name='select' type='checkbox' value=".$row[1]."></td>";
    echo "</tr>";
}
echo "</table><br>";

echo "<input class='bttn' type='submit' value='Delete Exam' name='delete'>";
echo " <input class='bttn' type='submit' value='Edit Exam' name='edit' > ";
echo "</form>"
?>

</td>
</tr>
<tr>
<td class="td" colspan="2" height="10%">
Status Bar:
<span id="black">
<?php 
if(!isset($_REQUEST['logout']))
{
include('delete.php');

if(isset($_POST['edit'])){

    header('location:editexam.php?id='.$_POST['select']);
    }

}
else
{
echo $_REQUEST['logout'];
    }
?>

</span>
<span class="logout"><a href="logout-handler.php">LOGOUT</a></span>
</td>
</tr>
</table>


</body>
</html>

现在在这个页面我已经在每个考试前面添加了复选框和两个按钮,一个用于删除考试永久性,第二个用于编辑考试。在编辑考试时每当我选择任何1个考试(通过复选框)并单击编辑以下结果显示(显示选择考试商务的示例):

Unknown column 'Commerce' in 'where clause' 

editexam.php 的代码如下:

<?php
include('dbconfig.php');
if(isset($_REQUEST['id'])){
    if($_REQUEST['id']=='')
    {
        header('location:manageexam.php?message2=Error: Please select a Value!');
    }
    else{
$id=$_REQUEST['id'];
$query="select * from examsmeta where SubId=".$id;
$res=mysql_query($query) or die(mysql_error());
$row=mysql_fetch_assoc($res);
}
}
?>
<!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>Admin |Edit Exam</title>
<link rel="stylesheet" type="text/css" href="style1.css">
<link rel="stylesheet" type="text/css" href="datepickr.css" />
<style>
.active5{
    color:#900;}
</style>
</head>

<body>
<!--text editor.-->
<script type="text/javascript" src="tinymce/tinymce.min.js"></script>

<script type="text/javascript">tinymce.init({
selector: "textarea",
// ===========================================
// INCLUDE THE PLUGIN
// ===========================================
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste jbimages"
],
// ===========================================
// PUT PLUGIN'S BUTTON on the toolbar
// ===========================================
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",
// ===========================================
// SET RELATIVE_URLS to FALSE (This is required for images to display properly)
// ===========================================
relative_urls: false
});</script>
<!--text editor script close-->

<?php include('livetime.php');?>
<table width="100%" class="table">
<tr>
<th class="th" align="left" colspan="2" >
<?php
session_start();
if($_SESSION['username'])
echo "<span id='welcome'>Congratulation, <span id='company'> ".$_SESSION['username']."</span> you are logged in!</span>";
else
die("You Must be logged in!");
?>
<span class="clock"><span id="clockbox"></span></span></th>
</tr>
<tr>
<td valign="top" class="tdleft"><br>
<span class="message"> Admin Controller</span>
<?php include('menu.php');?>
</td>

<td bgcolor="#FFFFCC" valign="top" style="padding:5px;">

<h2>Edit Exams Available </h2>

<form id="regform" action="" method="post">

<div class="wrapper">
<strong>Subject Name: </strong>
<div class="bg">

<input class="input" type="text" value="<?php if(isset($_REQUEST['id'])){
echo $row['name'];
}
?>" name="name"/>
</div>
</div>

<div class="wrapper">
<strong>Description:</strong>
<div class="bg">
<textarea class="textbox"  name="description">
<?php if(isset($_REQUEST['id']))
{
echo $row['description']; 
} ?>
</textarea>
<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
</div>
</div>
<br>
<div class="bttnalign"><a href="editexam.php?id=0"><input class="bttn" type="button" value="Clear">
  <input class="bttn" type="submit" name="submit" value="Update"/>
</a>
</div>
</form>

</td>
</tr>
<tr>

<td class="td" colspan="2" height="10%">
Status Bar:
<span id="black">
<?php

if(isset($_POST['submit']))
{
    $na=$_POST['name'];
    $nad=$_POST['description'];
    $rid=$_POST['id'];
    $nupdate=mysql_query("UPDATE examsmeta SET Name='".$na."',Description='".$nad."' WHERE SubId='".$rid."'") or die(mysql_error());

header("location:manageexam.php?message2=Data Updated Successfully!");


}
?>
</span>
<span class="logout"><a href="logout-handler.php">LOGOUT</a></span>

</td>
</tr>
</table>
<!--Date Picker-->
<script type="text/javascript" src="datepickr.min.js"></script>
<script type="text/javascript">
            new datepickr('datepick', {
                'dateFormat': 'm/d/Y'
            });
        </script>
<!--Date Picker closed-->
</body>
</html>

我做错了什么,有人解释一下吗?

1 个答案:

答案 0 :(得分:0)

您正在传递$row[1]作为参数,我认为这是具有名称的列。 更改以下代码:

 echo "<td><input name='select' type='checkbox' value=".$row[1]."></td>";

echo "<td><input name='select' type='checkbox' value=".$row[0]."></td>";

这将传递id by参数,(我假设id列位于0位置)/