Home > Backend Development > PHP Tutorial > php小白求教form display and update mysql的问题, 可以正常dispaly,无法update

php小白求教form display and update mysql的问题, 可以正常dispaly,无法update

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:47:29
Original
982 people have browsed it

<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>
Copy after login
Copy after login
<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>
Copy after login
Copy after login

php小白求教form display and update mysql的问题, 可以正常dispaly,无法update

php小白求教form display and update mysql的问题, 可以正常dispaly,无法update

回复内容:

<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>
Copy after login
Copy after login
<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>
Copy after login
Copy after login

php小白求教form display and update mysql的问题, 可以正常dispaly,无法update

php小白求教form display and update mysql的问题, 可以正常dispaly,无法update

是不是数据库查询用户权限不够呢?打开phpmyadmin看看~

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template