我对此很新。我想为php中的每一行创建带有编辑字段的表单。当我运行我的代码时,编辑的值不会在主页面中更新,但是当我回显查询时它正在正确运行。错误在哪里。?请帮助
table1.php
<?php
include('config\dbconfig.php');
$row = mysql_query("select * from admin");
if (isset($_POST['submit']))
{
if ($_POST['submit'] == 'Submit')
{ $uid = $_POST['uid'];
$name = $_POST['name'];
$uid = $_POST['uid'];
$email_id = $_POST['email_id'];
$password = $_POST['password'];
$gender = $_POST['gender'];
$address = $_POST['address'];
$qualification = implode(",",$_POST['qualification']);
$bdaytime = $_POST['bdaytime'];
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["myimage"]["name"]);
if (move_uploaded_file($_FILES["myimage"]["tmp_name"], $target_file))
{
echo "The file ". basename( $_FILES["myimage"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
$b=$_FILES["myimage"]["name"] ;
if($_REQUEST['uid']=="")
{
$sql = "INSERT INTO `admin`
(`uid`,`name`,`email`, `password`,
`gender`,`address`,`qualification`,
`bdaytime`,`myimage`)
VALUES ('$uid','$name','$email_id',
DES_ENCRYPT('$password'),
'$gender','$address','$qualification',
'$bdaytime','$b')";
echo $sql;
//mysql_query($sql);
} else {
$sql = "UPDATE `admin` SET `name`='$name', `email`='$email',
`password`='DES_ENCRYPT('$password')',
`gender`='$gender', `address`='$address',
`qualification`='$qualification',
`bdaytime`='$bdaytime'
WHERE id=".$_REQUEST['uid'];
echo $sql;
//mysql_query($sql);
}
}
}
$f=mysql_query("select * from admin where id=$_GET[id]");
$row=mysql_fetch_array($f);
$name=$row['name'];
$email=$row['email'];
$password=$row['password'];
$gender=$row['gender'];
$address=$row['address'];
$bdaytime= $row['bdaytime'];
$qualification= $row['qualification'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form action = "" method = "POST" enctype="multipart/form-data">
<input type="text" name="uid" value="<?php echo $_GET['id'];?>">
Name : <input type="text" name="name" value="<?php echo $name;?>" />
<br>
Email ID : <input type="text" name="email_id" value="<?php echo $email;?>"/>
<br>
Password : <input type="password" name="password" value="<?php echo $password;?>"/>
<br>
Gender : <input type="radio" name="gender" value="male">
<?php
if($gender=='male')
{
echo 'checked';
}else
{echo ''; }
?> Male <br>
<input type="radio" name="gender" value="female">
<?php
if($gender=='female') {
echo 'checked' ;
}else {
echo " ";
}
?> Female <br>
Address : <input type="text" name="address" value="<?php echo $address;?>" />
<br>
Qualification : <input type="checkbox" name="qualification[]" value="12th" >
<?php
if($gender=='12th') {
echo 'checked';
}else {
echo '';
}
?> 12th
<input type="checkbox" name="qualification[]" value="btech">
<?php
if($gender=='btech'){
echo 'checked';
}else{
echo '';
}
?> B.Tech <br>
<input type="checkbox" name="qualification[]" value="mtech" >
<?php
if($gender=='mtech'){
echo 'checked';
}else{
echo '';
}
?> M.Tech <br>
Birthday (date and time):
<input type="datetime-local" name="bdaytime" value="<?php echo $bdaytime;?>" >
<br>
Myimage : <input type="file" name="myimage">
<br>
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
</form>
</body>
</html>
的index.php
<?php
include('config\dbconfig.php');
//print_r ($_REQUEST);
$row = mysql_query("select * from admin");
/*echo "<table>";*/
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin - Bootstrap Admin Template</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/sb-admin.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="css/plugins/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<?php
echo $_GET['msg'];
?>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>email</th>
<th>password</th>
<th>gender</th>
<th>address</th>
<th>qualification</th>
<th>bdaytime</th>
<th>Image</th>
<th>action</th>
</tr>
</thead>
<tbody>
<?php
while($column = mysql_fetch_array($row)) {
echo "<tr><td>".$column['id'].
"</td><td>".$column['name'].
"</td><td>".$column['email'].
"</td><td>".$column['password'].
"</td><td>".$column['gender'].
"</td><td>".$column['address'].
"</td><td>".$column['qualification'].
"</td><td>".$column['bdaytime'].
"</td><td>".$column['myimage'].
"</td><td><a href='delete.php?id=$column[id]'>Delete</a> <a href='table1.php?id=$column[id]'>Edit</a></td></tr>" ;
}
?>
</tbody>
</table>
delete.php
<?php
include('config\dbconfig.php');
if(isset($_GET['id']))
{
$c= mysql_query("delete from `admin` WHERE id=$_GET[id]");
if($c==1)
$e="Rowdeleted";
if($c==0)
$e="Rownotdeleted";
header("Location: index.php?msg=$e");
}
?>