search
HomeBackend DevelopmentPHP Tutorial请问我这个 通讯簿浏览器 为什么没有数据显示呀?谢谢

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

   


      php_通讯簿浏览器
      
   
   
      

通讯簿浏览器


      

         function check_mysql(){
        if(mysql_errno()>0)
         echo "
 MySQL错误". mysql_errno().":".mysql_error();
      }
      $db= mysql_connect("localhost","root","");
      if(!$db)
        echo "数据库连接失败";
      @mysql_query("set names 'gb2312'");
      mysql_select_db("maildb");
      check_mysql();
      if(isset($left)){
         if($id        $query="SELECT id,name,email FROM addressbook WHERE id        $result=mysql_query($query);
        check_mysql();
        $row=mysql_fetch_row($result);
        $id=$row[0]; $name=$row[1]; $email=$row[2];
      }
      if(isset($right)){
        $query="SELECT id,name,email FROM addressbook ORDER BY id DESC";
        $result=mysql_query($query);
        $row=mysql_fetch_row($result);
        $max=$row[0];
        if($id==$max) {$id=$max-1;$message="这是最后1条信息";}
        $query="SELECT id,name,email FROM addressbook WHERE id>'$id'";
        $result=mysql_query($query);
        check_mysql();
        $row=mysql_fetch_row($result);
        $id=$row[0]; $name=$row[1]; $email=$row[2];
      }
      if(isset($search)){
        $id=0;
        $query="SELECT id,name,email FROM addressbook WHERE (name='$name' and id>'$id')";
        $result=mysql_query($query);
        check_mysql();
        $row=mysql_fetch_row($result);
        if($row[0]>0){
           $id=$row[0]; $name=$row[1]; $email=$row[2];
      }
      else{
        $name=""; $email=""; $message="记录不存在";
       }
     }
     if(isset($add)){
      $query="INSERT INTO addressbook(name,email) VALUES('$name','$email')";
      $result=mysql_query($query);
      check_mysql();
      $id=mysql_insert_id();
      $message="记录已添加(id='$id')";
    }
if(isset($update))   {
      $query="UPDATE addressbook SET name='$name', email='$email' WHERE id='$id'";
      $result=mysql_query($query);
      check_mysql();
      $message="记录已更新(id='$id')";
    }
    if(isset($delete)){
      $query="DELETE FROM addressbook WHERE id='$id'";
      $result=mysql_query($query);
      check_mysql();
      $name=""; $email="";
      $message="记录已删除(id='$id')";
      $sql="alter table addressbook drop id";
      mysql_query($sql);
      $sql="alter table addressbook add id int auto_increment primary key";
      mysql_query($sql);
    }
    $name=trim($name); $email= trim($email);
?> 
      
name: 
 />

      
email address 
 />

      

         ">
         

      

         
         
          />
         if(isset($message))
         echo"

$message";
   ?>
      

   



回复讨论(解决方案)

请求大神测试指导!谢谢!

 $query="SELECT id,name,email FROM addressbook WHERE (name='$name' and id>'$id')";

id是数值类型,不要用引号,应改为
 $query="SELECT id,name,email FROM addressbook WHERE (name='$name' and id>$id)";

 $query="SELECT id,name,email FROM addressbook WHERE (name='$name' and id>'$id')";

id是数值类型,不要用引号,应改为
 $query="SELECT id,name,email FROM addressbook WHERE (name='$name' and id>$id)";



不行 !去掉引号还是无数据显示的!

请求大神测试指导!谢谢!

if(isset( $left)){
从未对 $left 赋过值,所以 $left 并不存在
因此不会进入查询分支,自然也就不会有数据了

$left变量你没有定义,不会进入下面的分支啊。

 if(isset($left)){

if(isset( $left)){
从未对 $left 赋过值,所以 $left 并不存在
因此不会进入查询分支,自然也就不会有数据了



请问根据上面的具体怎么定义赋值呀,望具体代码指导!谢谢!

$left变量你没有定义,不会进入下面的分支啊。

 if(isset($left)){



请问根据上面的具体怎么定义赋值呀,望具体代码指导!谢谢!

     


extract($_POST); //加上这句
      function check_mysql(){

     


extract($_POST); //加上这句
      function check_mysql(){

您好 !现在 添加、更新、删除功能OK了!但是左右查询及查询关键字无法实现,还是不显示!请大神继续指导下, 谢谢!

可以了  谢谢版主!!

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
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function