首頁 web前端 js教程 PHP與SQL語句常用大全

PHP與SQL語句常用大全

Dec 22, 2016 pm 02:09 PM
php sql語句

本文介紹PHP與SQL語句常用大全,具體程式碼如下所述:

<?php
$conn=mysql_connect("localhost","root","root");
mysql_select_db("db_database17",$conn);
mysql_query("set names gb2312");
?>
<?php
$sql1=mysql_query("select usernc,face,ip,email,qq from tb_user where id=&#39;".$info["userid"]."&#39;",$conn);
$info1=mysql_fetch_array($sql1);
echo $info1["face"];
?>
action="savereg.php"
<input type="text" name="usernc"
<input type="text" name="userpwd"
<input type="text" name="truename"
<?php
if(mysql_query("insert into tb_user(usernc,userpwd,truename,email,qq,tel,ip,address,face,regtime,sex,usertype) values(&#39;".$usernc."&#39;,&#39;".md5(trim($_POST["userpwd"]))."&#39;,&#39;".$_POST["truename"]."&#39;,&#39;".$_POST["email"]."&#39;,&#39;".$_POST["qq"]."&#39;,&#39;".$_POST["tel"]."&#39;,&#39;".$ip."&#39;,&#39;".$_POST["address"]."&#39;,&#39;".$_POST["face"]."&#39;,&#39;".date("Y-m-d H:i:s")."&#39;,&#39;".$_POST["sex"]."&#39;,&#39;0&#39;)",$conn)){
if($_SESSION["unc"]!=""){
  session_unregister("unc");
  }
session_register("unc");
  $_SESSION["unc"]=$usernc; 
  echo "<script>alert(&#39;注册成功!&#39;);history.back();</script>";
}else{
  echo "<script>alert(&#39;注册失败!&#39;);history.back();</script>";
}
?>
<?php
  $sql=mysql_query("select count(*) as total from tb_leaveword ",$conn);//把查询的结果存入total中
  $info=mysql_fetch_array($sql);
  $total=$info[total];
  if($total==0){
   echo "<div align=center>对不起,暂无留言!</div>";
  }else{
   if(!isset($_GET["page"]) || !is_numeric($_GET["page"])){
     $page=1;
   }else{
     $page=intval($_GET["page"]);
   }
   $pagesize=3;
   if($total%$pagesize==0){
     $pagecount=intval($total/$pagesize);
   }else{
     $pagecount=ceil($total/$pagesize);
   }
   $sql=mysql_query("select * from tb_leaveword order by createtime desc limit ".($page-1)*$pagesize.",$pagesize ",$conn);
   while($info=mysql_fetch_array($sql)){
   ?>
<table width="520" height="5" border="0" align="center" cellpadding="0" cellspacing="0">
   <tr>
    <td></td>
   </tr>
  </table>
   <table width="550" height="155" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FCD424">
    <tr>
     <td bgcolor="#FFFFFF" valign="top"><table width="550" height="24" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
       <td width="450" background="images/dh_back_1.gif"> 主  题:<?php echo unhtml($info["title"]);?></td>
       <td width="100" background="images/dh_back_1.gif"><div align="center">
   <script language="javascript">
    function openeditwindow(x){
    window.open("editleaveword.php?id="+x,"newframe","top=100,left=200,width=450,height=280,menubar=no,location=no,scrollbars=no,status=no");
   }
   </script>
  <?php
   $sqlu=mysql_query("select usernc from tb_user where id=&#39;".$info["userid"]."&#39;",$conn);
   $infou=mysql_fetch_array($sqlu);
   if($infou["usernc"]==$_SESSION["unc"]){
  ?>
    <a href="javascript:openeditwindow(<?php echo $info[id];?>)" class="a1">编辑</a>
  <?php
   }
  ?>
    
  <?php
   if($_SESSION["unc"]!=""){
   $sqld=mysql_query("select usertype from tb_user where usernc=&#39;".$_SESSION["unc"]."&#39;",$conn);
        $infod=mysql_fetch_array($sqld);
   if($infod["usertype"]==1){
   ?>
   <a href="javascript:if(window.confirm(&#39;确定删除该留言信息么?&#39;)==true){window.location.href=&#39;deleteleaveword.php?id=<?php echo $info[id];?>&#39;;}" class="a1">删除</a>
  <?php
   }
   }
  ?>
   </div></td>
      </tr>
     </table>
      <table width="550" height="5" border="0" align="center" cellpadding="0" cellspacing="0">
       <tr>
        <td></td>
       </tr>
      </table>
  <table width="550" height="120" border="0" align="center" cellpadding="0" cellspacing="0">
       <tr>
        <td width="150" height="90"><div align="center"><img src="<?php
   $sql1=mysql_query("select usernc,face,ip,email,qq from tb_user where id=&#39;".$info["userid"]."&#39;",$conn);
   $info1=mysql_fetch_array($sql1);
   echo $info1["face"];
   ?>" /><br><?php echo $info1["usernc"];?></div></td>
        <td width="10" background="images/line_down.gif"></td>
        <td width="390" rowspan="2"><?php echo unhtml($info["content"]);?></td>
       </tr>
       <tr>
        <td height="30"><div align="center"><img src="images/email.gif" width="45" height="16" alt="<?php echo $info1[email];?>"/><img src="images/ip.gif" width="55" height="16" alt="<?php echo $info1[ip];?>"/><img src="images/qq.gif" width="45" height="16" alt="<?php echo $info1[qq];?>"/></div></td>
        <td width="10" background="images/line_down.gif"></td>
       </tr>
      </table>
  </td>
    </tr>
   </table>
  <?php
  }
  }
  ?>
   
  <table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
     <tr>
      <td width="351"><div align="left">共有留言 <?php echo $total;?> 条 每页显示 <?php echo $pagesize;?> 条 第 <?php echo $page;?> 页/共 <?php echo $pagecount;?> 页</div></td>
      <td width="199"><div align="right"><a href="<?php echo $_SERVER["PHP_SELF"]?>?page=1" class="a1">首页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php
  if($page>1)
   echo $page-1;
  else
   echo 1;
   ?>" class="a1">上一页</a> <a href="<?php echo $_SERVER["PHP_SELF"]?>?page=<?php
  if($page<$pagecount)
   echo $page+1;
  else
   echo $pagecount;
   ?>
登入後複製


本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PHP的未來:改編和創新 PHP的未來:改編和創新 Apr 11, 2025 am 12:01 AM

PHP的未來將通過適應新技術趨勢和引入創新特性來實現:1)適應云計算、容器化和微服務架構,支持Docker和Kubernetes;2)引入JIT編譯器和枚舉類型,提升性能和數據處理效率;3)持續優化性能和推廣最佳實踐。

sql server怎麼用sql語句創建表 sql server怎麼用sql語句創建表 Apr 09, 2025 pm 03:48 PM

在 SQL Server 中使用 SQL 語句創建表的方法:打開 SQL Server Management Studio 並連接到數據庫服務器。選擇要創建表的數據庫。輸入 CREATE TABLE 語句,指定表名、列名、數據類型和約束。單擊執行按鈕創建表。

PHP與Python:了解差異 PHP與Python:了解差異 Apr 11, 2025 am 12:15 AM

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PostgreSQL如何添加列? PostgreSQL如何添加列? Apr 09, 2025 pm 12:36 PM

PostgreSQL 添加列的方法為使用 ALTER TABLE 命令並考慮以下細節:數據類型:選擇適合新列存儲數據的類型,如 INT 或 VARCHAR。默認值:通過 DEFAULT 關鍵字指定新列的默認值,避免值為 NULL。約束條件:根據需要添加 NOT NULL、UNIQUE 或 CHECK 約束條件。並發操作:使用事務或其他並發控制機制處理添加列時的鎖衝突。

SQL注入怎麼判斷 SQL注入怎麼判斷 Apr 09, 2025 pm 04:18 PM

判斷 SQL 注入的方法包括:檢測可疑輸入、查看原始 SQL 語句、使用檢測工具、查看數據庫日誌和進行滲透測試。檢測到注入後,採取措施修補漏洞、驗證補丁、定期監控、提高開發人員意識。

sql語句三個表連接怎麼寫教程 sql語句三個表連接怎麼寫教程 Apr 09, 2025 pm 02:03 PM

本文介紹了一種使用 SQL 語句連接三個表的詳細教程,指導讀者逐步了解如何有效地關聯不同表中的數據。通過示例和詳細的語法講解,本文將幫助您掌握 SQL 中表的連接技術,從而能夠高效地從數據庫中檢索關聯信息。

PHP的當前狀態:查看網絡開發趨勢 PHP的當前狀態:查看網絡開發趨勢 Apr 13, 2025 am 12:20 AM

PHP在現代Web開發中仍然重要,尤其在內容管理和電子商務平台。 1)PHP擁有豐富的生態系統和強大框架支持,如Laravel和Symfony。 2)性能優化可通過OPcache和Nginx實現。 3)PHP8.0引入JIT編譯器,提升性能。 4)雲原生應用通過Docker和Kubernetes部署,提高靈活性和可擴展性。

SQL刪除行後如何恢復數據 SQL刪除行後如何恢復數據 Apr 09, 2025 pm 12:21 PM

直接從數據庫中恢復被刪除的行通常是不可能的,除非有備份或事務回滾機制。關鍵點:事務回滾:在事務未提交前執行ROLLBACK可恢復數據。備份:定期備份數據庫可用於快速恢復數據。數據庫快照:可創建數據庫只讀副本,在數據誤刪後恢復數據。慎用DELETE語句:仔細檢查條件,避免誤刪數據。使用WHERE子句:明確指定要刪除的數據。使用測試環境:在執行DELETE操作前進行測試。

See all articles