I'm tryig to create a text input on my page to be able to receive a username which is on my database and return another information of himself, how can i do it? For example entering a name and returning his telephone number. i have just no idea how to start. Thanks
2条回答 默认 最新
- dongmo9996 2014-11-16 11:16关注
Here's the working code. But learn the basics first.
index.html
<!DOCTYPE html> <html> <head> <title>Index page</title> </head> <body> <form method="POST" action="retrieve.php"> Enter your name : <input type="text" name='username'><br><br> <input type="submit" name="submit"> </form> </body> </html>
retrieve.php
<?php //Database connection $connection = mysqli_connect("localhost","username","password","database_name"); if (isset($_POST['submit'])) { $uname = $_POST['username']; // sql query and user is the table name $query = "SELECT * FROM `user` WHERE user_name='$uname'"; // query to execute $result = mysqli_query($connection,$query); if (!$result) { echo "fails"; } while($row = mysqli_fetch_array($result)) { $telephone_no = $row['phoneno']; $country_name = $row['country']; echo "Your results for name - " . $uname; echo "<br><br>"; echo "Telelephone is : " . $telephone_no; echo "<br>"; echo "Country name is : " . $country_name; } } ?>
Database structure : (User table)
To test the code, insert a person details in
PHPMyadmin
insert tab.(Leave id alone as it was set to an auto-increment).本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 多址通信方式的抗噪声性能和系统容量对比
- ¥15 winform的chart曲线生成时有凸起
- ¥15 msix packaging tool打包问题
- ¥15 finalshell节点的搭建代码和那个端口代码教程
- ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
- ¥15 Centos / PETSc / PETGEM
- ¥15 centos7.9 IPv6端口telnet和端口监控问题
- ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
- ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
- ¥20 海浪数据 南海地区海况数据,波浪数据