Home > Backend Development > PHP Tutorial > 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

墨辰丷
Release: 2023-03-30 21:26:02
Original
2155 people have browsed it

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>";
  }
?>
Copy after login

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/>";
  }
?>
Copy after login

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>";
}
?>
Copy after login

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>";
?>
Copy after login

delete_session.php is as follows:

<?php
  if(isset($_SESSION["id"]))
  {
   unset($_SESSION["id"]);
  }
  echo "<script>alert(&#39;清除成功&#39;);</script>";
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template