<code class="lang-php"><?php define('DB_NAME', 'form'); define('DB_USER', 'root'); define('DB_PASSWORD', '123456'); define('DB_HOST', 'localhost'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!$link) { die('could not connect: ' . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $link); if (!$db_selected) { die('Can\'t use ' .DB_NAME .':' . mysql_error()); } $query = "SELECT * FROM articles"; $result = mysql_query($query) or die(mysql_error()); ?></code>
<code><div class="content-holder"> <form action="" method="post"> <table border="1" cellpadding="10" id="ViewTable"> <tr> <th>title</th> <th>id</th> </tr> <?php while($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; ?> <tr> <td> <input type="textbox" class="TextAreaTitle" name="title" value="<?=$title?>"> <input type="hidden" name="id" value="<?=$title?>"> </td> <td>=$id?></td> </tr> <?php } ?> </table> <input type="submit" name="update" class="submitlink" value="update"> </form> </div> <?php if(isset($_POST['update'])) { for ($i=count($_POST['id']); $i--;) { $id = $_POST['title'][$i]; $title = $_POST['id'][$i]; mysql_query("UPDATE articles SET title= $title WHERE id= $id "); } } ?></code>
<code class="lang-php"><?php define('DB_NAME', 'form'); define('DB_USER', 'root'); define('DB_PASSWORD', '123456'); define('DB_HOST', 'localhost'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!$link) { die('could not connect: ' . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $link); if (!$db_selected) { die('Can\'t use ' .DB_NAME .':' . mysql_error()); } $query = "SELECT * FROM articles"; $result = mysql_query($query) or die(mysql_error()); ?></code>
<code><div class="content-holder"> <form action="" method="post"> <table border="1" cellpadding="10" id="ViewTable"> <tr> <th>title</th> <th>id</th> </tr> <?php while($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; ?> <tr> <td> <input type="textbox" class="TextAreaTitle" name="title" value="<?=$title?>"> <input type="hidden" name="id" value="<?=$title?>"> </td> <td>=$id?></td> </tr> <?php } ?> </table> <input type="submit" name="update" class="submitlink" value="update"> </form> </div> <?php if(isset($_POST['update'])) { for ($i=count($_POST['id']); $i--;) { $id = $_POST['title'][$i]; $title = $_POST['id'][$i]; mysql_query("UPDATE articles SET title= $title WHERE id= $id "); } } ?></code>
是不是数据库查询用户权限不够呢?打开phpmyadmin
看看~