上面这段代码可以正常插入数据。
<?php
include_once 'conn.php';
if($_POST['submit'])
{
$sql = "insert into account (id,date,money,item)".
"values ('',now(),'$_POST[money]','$_POST[item]')";
$conn->query($sql);
} ?>
<body>
<form name="account" action="index.php" method="POST">
时间:<input type="text" name="time" value="" size="10"/> <br>
金额:<input type="text" name="money" value="" size="10" /><BR>
事项:<input type="text" name="item" value="" size="20" /><BR>
分类:<select name="sort">
<option value="volvo">主食</option>
<option value="saab">零食点心</option>
</select><BR>
<input type="submit" name="submit" value="提交" />
</form>
下面那段代码页面什么都没显示。也没提示错误。
<?php
$sql="select * from account";
$results=mysql_query($sql);
while($row=mysql_fetch_array($results)){
?>
<table border="1">
<tbody>
<tr>
<td><?php echo $row[id];?></td>
<td><?php echo $row[date];?></td>
<td><?php echo $row[money];?></td>
<td><?php echo $row[item];?></td>
</tr>
</tbody>
</table>
谢谢回复!
<?php
include_once 'conn.php';
if($_POST['submit'])
{
$sql = "insert into account (id,date,money,item)".
"values ('',now(),'$_POST[money]','$_POST[item]')";
$conn->query($sql);
} ?>
<body>
<form name="account" action="index.php" method="POST">
时间:<input type="text" name="time" value="" size="10"/> <br>
金额:<input type="text" name="money" value="" size="10" /><BR>
事项:<input type="text" name="item" value="" size="20" /><BR>
分类:<select name="sort">
<option value="volvo">主食</option>
<option value="saab">零食点心</option>
</select><BR>
<input type="submit" name="submit" value="提交" />
</form>
下面那段代码页面什么都没显示。也没提示错误。
<?php
$sql="select * from account";
$results=mysql_query($sql);
while($row=mysql_fetch_array($results)){
?>
<table border="1">
<tbody>
<tr>
<td><?php echo $row[id];?></td>
<td><?php echo $row[date];?></td>
<td><?php echo $row[money];?></td>
<td><?php echo $row[item];?></td>
</tr>
</tbody>
</table>
谢谢回复!
<?php
$sql="select * from account";
$results=mysql_query($sql);
while($row=mysql_fetch_array($results)){
?>
<table border="1">
<tbody>
<tr>
<td><?php echo $row[id];?></td>
<td><?php echo $row[date];?></td>
<td><?php echo $row[money];?></td>
<td><?php echo $row[item];?></td>
</tr>
</tbody>
</table>
<?php }?>
少了这个<?php }?>?
-----------------------------------------------
能不能給點簡單示例代碼看看,謝謝。
"values ('',now(),'$_POST[money]','$_POST[item]')";
但你的数据库类把错误吞掉了
其实有问题的代码在下面那一片。就算加一个<?php } ?> 也还是不能正常显示数据库内容。
大家讨论的上面那排代码正常的,可以添加数据。
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<?php
include_once 'conn.php';
if($_POST['submit'])
{
$sql = "insert into account (id,date,money,item)".
"values ('',now(),'$_POST[money]','$_POST[item]')";
$conn->query($sql);
} ?>
<body>
<form name="account" action="index.php" method="POST">
时间:<input type="text" name="time" value="" size="10"/> <br>
金额:<input type="text" name="money" value="" size="10" /><BR>
事项:<input type="text" name="item" value="" size="20" /><BR>
分类:<select name="sort">
<option value="volvo">主食</option>
<option value="saab">零食点心</option>
<option value="fiat">个人用品</option>
<option value="saab">集体用品</option>
<option value="audi">办公用品</option>
<option value="volvo">路费</option>
<option value="saab">公司报销</option>
<option value="saab">集体报销</option>
<option value="saab">公司报销</option>
<option value="fiat">不知道</option>
</select><BR>
<input type="submit" name="submit" value="提交" />
</form>
<?php
$sql="select * from account";
$results=mysql_query($sql);
while($row=mysql_fetch_array($results)){
?>
<table border="1">
<tbody>
<tr>
<td><?php echo $row[id];?></td>
<td><?php echo $row[date];?></td>
<td><?php echo $row[money];?></td>
<td><?php echo $row[item];?></td>
</tr>
</tbody>
</table> <?php
}
?>
</body>
</html>
Warning: mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in D:\wamp\www\a1\INDEX.php on line 42Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\wamp\www\a1\INDEX.php on line 42Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\wamp\www\a1\INDEX.php on line 43
出错的
14行 if($_POST['submit'])
42行 $results=mysql_query($sql);
43行 while($row=mysql_fetch_array($results)){