[请益] 通讯录新增?

楼主: joinbee (farewell 我的童年)   2021-11-13 21:10:53
<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
作者: kattte (诚实面对自己吧!)   2021-11-13 21:34:00
1. 确定 $username,$phone 有东西2. 确定你组的SQL长啥样子3. 把你在2组的SQL 扔进DB 执行看看4. 确定你知道你自己在做什么
作者: LMGG (联盟GG)   2021-11-14 10:14:00
在$username 底下用echo 或 print呼叫出来看看有没有取得值,有值就查看SQL 组合,一样呼叫出来查看,如果$username没值,就回头查为什么没值
作者: kattte (诚实面对自己吧!)   2021-11-14 11:50:00
...你这个 form 会post资料给 addtx.php 那你有给我们看addtx.php里做了什么吗?
楼主: joinbee (farewell 我的童年)   2021-11-14 16:42:00
addtx.php就把数据库的资料印出来而已,看起来印出来好像没什么问题?应该是没什么关系?txinfo资料表就两个字段,一个是username一个是phone都是varchar,我有echo$username跟$phone里面的确是没有东西,我在猜会不会是HTML的问题?
作者: zx4109 (阿仲)   2021-11-14 16:56:00
你要不要放到 github gist 上或是类似功能的平台这样大家能比较方便看
楼主: joinbee (farewell 我的童年)   2021-11-14 19:36:00
问题解决了,把addtx.php放到同一个php底下一切就正常了
作者: LMGG (联盟GG)   2021-11-14 19:37:00
前端送资料去addtx.php,要把接收资料的程式码放到那里才对

Links booklink

Contact Us: admin [ a t ] ucptt.com