0

当我尝试更新来自表的数据时,它会使表中的该行变为空白..

这是我的代码:

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>&nbsp;</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 */;

我是新手。总是欢迎提出建议...

4

1 回答 1

0
  1. 您以错误的方式管理表单字段的名称。你已经给name='name'了手机、电子邮件和出版商名称字段。
  2. 此外,您在表单中已将名称命名为“标题”,但您访问的是$_POST['book_title']. 作者和版权年份字段也是如此。使用与表单中给出的名称相同的名称,以通过 POST 数组访问。

纠正这些事情,然后它会起作用。

于 2013-01-17T05:18:11.317 回答