<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