关于mysql_fetch_row的问题
请问各位高手能用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)参数必须是资源类型的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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-

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.

Alipay PHP...

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' =>

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

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

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

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