Home  >  Article  >  Backend Development  >  How to use PHP to read, judge and log in to the database

How to use PHP to read, judge and log in to the database

墨辰丷
墨辰丷Original
2018-06-08 16:47:132139browse

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 (&#39;".$_SESSION["id"]."&#39;,&#39;".$id."&#39;,&#39;no&#39;)";
  $query=mysql_query($sql);
  if($query)
  {
    echo "<script>alert(&#39;?????????&#39;);</script>";
    echo "<script>window.location.href=&#39;reg.php&#39;</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=&#39;newfile.php?id=".$out["id"]."&#39;>查看邮件</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=&#39;".$_GET["id"]."&#39;";
  $result=mysql_query($sql);
 }
$out=mysql_fetch_array($result);
echo $out["content"]."<br/>";
echo $out["created_at"]."<br/>";
echo "<a href=&#39;send_email.php?id=".$out["id"]."&#39;>发送邮件</a><br/><hr>";
//看看有没有新邮件
$sql_search_email="select * from email where accepter_id=&#39;".$id."&#39;";
$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=&#39;see_email.php?id=".$result_email["id"]."&#39;>您有新邮件</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=&#39;delete_session.php&#39;>清除session</a>";
  echo "<a href=&#39;reg.php&#39;>重新注册</a>";
?>

delete_session.php is as follows:

<?php
  if(isset($_SESSION["id"]))
  {
   unset($_SESSION["id"]);
  }
  echo "<script>alert(&#39;清除成功&#39;);</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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn