Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 关于mysql_fetch_row的问题

关于mysql_fetch_row的问题

Jun 23, 2016 pm 02:09 PM

    请问各位高手能用if来判断mysql_fetch_row吗,我看到一个php视频中老师写的
if($row=mysql_fetch_row($res)),没有写错,就是一个=,视频中程序也正常运行了,
可是我按着写浏览器却总是提示这行语法有错误,请高手指点


回复讨论(解决方案)

while($row=mysql_fetch_row($res)){

}

LZ你浏览器提示的是怎么一个错误呢。
mysql_fetch_row()这条语句中的参数(也就是$res)必须是MYSQL返回的资源类型才行。
普通的自定义数组、PHP变量应该是不行的。
if($row = mysql_fetch_row($res))这句话是可以用的。

那种写法是可以的
建议你把错误信息贴出来以供分析

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
这是错误信息

那人家都告诉你了 说你用的参数不是一个有效的MYSQL返回资源类型
比如 你在数据库读取的时候
$a = mysql_query();
mysql_fetch_row($a);
这样才好用吧

这是写的代码

  $id=$_post['id'];
  
  $password=$_post['password'];

  $conn=mysql_connect("localhost","root","1234")or die("连接失败".mysql_errno());
  
  mysql_select_db("test",$conn)or die("选择数据库失败".mysql_errno());
  
  mysql_query('set names utf8') or die("设置编码失败".mysql_errno());
  
  $sql="select password from admin where id=$id";
  
  $res=mysql_query($sql,$conn);
  
  if ($row=mysql_fetch_row($res)){
  
   if ($row[1]==$password){
  
   header('location:empMain.php');
   exit();
   }
  }
       header('location:login.php');
        exit();
      
        mysql_free_result($res);
        mysql_close();
?>

resource(4) of type (mysql result)
 $res=mysql_query($sql,$conn);
  //LZ在这里var_dump($res),只要是显示resource(4) of type (mysql result)就对了
  //如果不是那就是之前数据库连接或者内容上的问题了吧
  if ($row=mysql_fetch_row($res)){


引发错误的不是数据库操作,而是
$id=$_post['id'];
$password=$_post['password'];
应为
$id=$_POST['id'];
$password=$_POST['password'];
注意,php的变量时大小写敏感的

由于并不存在 $_post 数组,而你又屏蔽了 NOTICE 级别的错误(不然早就发现了)
于是
$sql="select password from admin where id=$id";
变成了 $sql="select password from admin where id=";
显然是错误的!
因此导致 
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
的出现

楼主威武,语气极其自信,肯定,实力超凡啊

果断是参数类型的问题,mysql_fetch_row($res)参数必须是资源类型的

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles