当我尝试更新来自表的数据时,它会使表中的该行变为空白..
这是我的代码:
1)edit.php(我认为更新查询错误,但我不确定....)
<?php
require("config.php");
$id =$_REQUEST['id'];
$result = mysql_query("SELECT * FROM bookss WHERE id = '$id'");
$test = mysql_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$Title=$test['book_title'] ;
$Author_name= $test['author_name'] ;
$Mobile=$test['mobile'] ;
$Email=$test['email'] ;
$Publisher_name=$test['publisher_name'] ;
$Copy_right_year =$test['copy_right_year'] ;
if(isset($_POST['btnSubmit']))
{
$book_save = $_POST['book_title'];
$author_save = $_POST['author_name'];
$mobile_save = $_POST['mobile'];
$email_save = $_POST['email'];
$publisher_save = $_POST['publisher_name'];
$copy_right_save = $_POST['copy_right_year'];
mysql_query("UPDATE bookss SET book_title ='$book_save',author_name ='$author_save',
mobile ='$mobile_save',email ='$email_save',publisher_name ='$publisher_save',copy_right_year ='$copy_right_save' WHERE ID = '$id'")
or die(mysql_error());
echo "Saved!";
header("Location: view.php");
}
mysql_close($conn);
?>
<html">
<head>
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<table>
<tr>
<td>Title:</td>
<td><input type="text" name="title" value="<?php echo $Title ?>"/></td>
</tr>
<tr>
<td>Author</td>
<td><input type="text" name="author" value="<?php echo $Author_name ?>"/></td>
</tr>
<tr>
<td>Mobile</td>
<td><input type="text" name="name" value="<?php echo $Mobile ?>"/></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="name" value="<?php echo $Email ?>"/></td>
</tr>
<tr>
<td>Publisher Name</td>
<td><input type="text" name="name" value="<?php echo $Publisher_name ?>"/></td>
</tr>
<tr>
<td>Copyright Year</td>
<td><input type="text" name="copy" value="<?php echo $Copy_right_year ?>"/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="btnSubmit" value="Update" /></td>
</tr>
</table>
</body>
</html>
2)DATABASE(我的数据库)
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `idu3`
-- Table structure for table `bookss`
--
CREATE TABLE IF NOT EXISTS `bookss` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`book_title` varchar(255) NOT NULL,
`author_name` varchar(255) NOT NULL,
`mobile` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`publisher_name` varchar(255) NOT NULL,
`copy_right_year` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
--
-- Dumping data for table `bookss`
--
INSERT INTO `bookss` (`id`, `book_title`, `author_name`, `mobile`, `email`, `publisher_name`, `copy_right_year`) VALUES
(5, 'harshad heaven1', 'Harshad Patel', '8866672489', 'harshadheaven70@gmail.com', 'Friendz Company', '1990'),
(6, 'harshad heaven1', 'Harshad patel', '8866672489', 'harshadheaven70@gmail.com', 'Friendz Company', '1990'),
(7, '', '', '', '', '', ''),
(8, '', '', '', '', '', ''),
(9, '', '', '', '', '', ''),
(10, '', '', '', '', '', '');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
我是新手。总是欢迎提出建议...