Home >Backend Development >PHP Tutorial >How to use PHP to read, judge and log in to the database
This article mainly introduces how to use PHP to read, judge and log in to the database. Interested friends can refer to it. I hope it will be helpful to everyone.
The example in this article describes how PHP implements the method of identifying users to send emails through the get method. The details are as follows:
send_email.php is as follows:
<?php $conn=mysql_connect("localhost","root","admin"); mysql_select_db("songyunb_development",$conn); $id=$_GET["id"]; $sql="insert into email (sender_id,accepter_id,flag) values ('".$_SESSION["id"]."','".$id."','no')"; $query=mysql_query($sql); if($query) { echo "<script>alert('?????????');</script>"; echo "<script>window.location.href='reg.php'</script>"; } ?>
reg.php is as follows:
<?php $conn=mysql_connect("localhost","root","admin"); mysql_select_db("songyunb_development",$conn); $sql="select * from comments"; $query=mysql_query($sql); while($out=mysql_fetch_array($query)) { echo $out["content"]."-------<a href='newfile.php?id=".$out["id"]."'>查看邮件</a><br/>"; } ?>
newfile.php is as follows:
<?php $conn=mysql_connect("localhost","root","admin"); mysql_select_db("songyunb_development",$conn); $result=""; $id=""; if(isset($_GET["id"])) { $id=$_GET["id"]; $sql="select * from comments where id='".$_GET["id"]."'"; $result=mysql_query($sql); } $out=mysql_fetch_array($result); echo $out["content"]."<br/>"; echo $out["created_at"]."<br/>"; echo "<a href='send_email.php?id=".$out["id"]."'>发送邮件</a><br/><hr>"; //看看有没有新邮件 $sql_search_email="select * from email where accepter_id='".$id."'"; $query=mysql_query($sql_search_email); $result_email=mysql_fetch_array($query); if($result_email["accepter_id"]==$_SESSION["id"]&&$result_email["flag"]=="no") { echo "<strong><a href='see_email.php?id=".$result_email["id"]."'>您有新邮件</a></strong>"; } ?>
login.php is as follows:
<?php $conn=mysql_connect("localhost","root","admin"); mysql_select_db("songyunb_development",$conn); $_SESSION["id"]=15; echo "<a href='delete_session.php'>清除session</a>"; echo "<a href='reg.php'>重新注册</a>"; ?>
delete_session.php is as follows:
<?php if(isset($_SESSION["id"])) { unset($_SESSION["id"]); } echo "<script>alert('清除成功');</script>"; ?>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
Implemented a rating function based on jQuery through PHP and mysql
How to use and introduce the PHP Closure class
php ajax real-time input automatic search matching method
The above is the detailed content of How to use PHP to read, judge and log in to the database. For more information, please follow other related articles on the PHP Chinese website!