<html>
<head>
<title>新增通讯录</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body>
<div align="center">
<form action="addtx.php" name="txform" method="post">
<table border="1">
<tr>
<td>姓名:</td>
<td><input type="text" name="un"></td>
</tr>
<tr>
<td>手机:</td>
<td><input type="text" name="tel"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="addtxbtn"
value="新增" ></td>
</tr>
</table>
<?php
$con=mysqli_connect("localhost","root","","tongxunlu") or die('连线失败
'.mysqli_error());
mysqli_select_db($con,"tongxunlu");
//mysql_query("set names gb2312"); //如果页面字符集设
定为GB2312则需要加上这句
if(!empty($_POST)){
$username=$_POST['un'];
$phone=$_POST['tel'];
$addtx="insert into txinfo(username,phone) values
('$username','$phone')";
mysqli_query($con,$addtx);
}
?>
</form>
</div>
</body>
</html>
不好意思,上次没排好版,这次排好了,请问各位大大,我新增通讯录的资料按下新增,
数据库新增的字段却是空白的值,比如说我新增姓名为胖虎,电话123,通讯录却显示空
白或0,这是什么原因?
<html>
<head>
<title>显示通讯录</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body>
<div align="center">
<?php
$con=mysqli_connect('localhost','root','','tongxunlu') or die('连线失败
'.mysql_error());
mysqli_select_db($con,"tongxunlu");
//mysql_query("set names gb2312");
$showtx="select username,phone from txinfo ";
$result=mysqli_query($con,$showtx);
?>
<table border="1">
<?php
$num_rows=mysqli_num_rows($result);
if($num_rows>0)
{
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
?>
<tr>
<td>姓名</td>
<td><?php echo $row["username"]?></td>
</tr>
<tr>
<td>手机</td>
<td><?php echo $row["phone"]?></td>
</tr>
<?php }}?>
</table>
<a href="phonebook.php">输入电话</a>
</div>
</body>
</html>
上面是addtx.php
http://www.blueshop.com.tw/board/FUM20041006152627A9N/BRD20211110204009MKQ.html