Table of Contents
回复讨论(解决方案)

数据库服务

Jun 23, 2016 pm 01:31 PM

<?php header("content-type:text/html;charset=utf-8");	 	//编码include("conn/conn.php");							//链接数据库if(isset($_POST['xiugai'])){		//判断有没有修改按钮	$user=$_POST['user'];	        //定义用户名变量	$pwd=$_POST['pwd'];				//原密码变量	$xpwd=$_POST['xpwd'];					//新密码变量	$section=$_POST['section'];			//部门名称变量	$name=$_POST['name'];				//真实姓名变量	$insert=mysql_query("update tb_login set pwd='$xpwd',section='$section',name='$name' where user='$user' and pwd='$pwd'",$conn);		//更新数据库语句	echo mysql_error();	if($insert){//判断是否执行	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';		echo "<script>alert('?修改成功');window.location.href='index.php'</script>";			//修改成功	}	else{	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';		echo "<script>alert('?修改失败');window.location.href='guanli.php'</script>";		//修改失败	}}?>
Copy after login

这个是网页代码
<form action="guanli_ok.php" method="post" enctype="multipart/form-data" name="form2" id="form2">      <table width="527" height="282" border="0" cellpadding="0" cellspacing="0">        <tr>          <td width="194" height="46"><div align="left"><?php echo $_SESSION['user'];?> 用户信息修改</div></td>          <td width="333"><div align="left"></div></td>        </tr>         <tr>          <td height="46"><div align="right">用户名:</div></td>          <td><div align="left"><input type="text" name="user" readonly="readonly" value="<?php echo $_SESSION['user'];?>"/></div></td>        </tr>        <tr>          <td height="40"><div align="right">原密码:</div></td>          <td><div align="left"><input type="text" name="pwd" /></div></td>        </tr>        <tr>          <td height="30"><div align="right">新密码:</div></td>          <td><div align="left"><input type="text" name="xpwd" /></div></td>        </tr>        <tr>          <td height="30"><div align="right">确认密码:</div></td>          <td><div align="left"><input type="text" name"quren" /></div></td>        </tr>        <tr>          <td height="30"><div align="right">部门:</div></td>          <td><div align="left"><input type="text" name="section" /></div></td>        </tr>        <tr>          <td height="30"><div align="right">真实姓名:</div></td>          <td><div align="left"><input type="text" name="name" /></div></td>        </tr>        <tr>          <td height="30"> </td>          <td><input type="submit" name="xiugai" value="确认修改"/> </td>        </tr>      </table>    </form>
Copy after login


问题是最后就算我原密码是输入错误的提示也是修改成功跳转到了index.php页面  但是数据库没修改 原密码正确就一切正常


回复讨论(解决方案)

if($insert){//判断是否执行
这个判断是错误的
你只是检查了 update 命令是否有错,并没有检查到修改是否成功
mysql_affected_rows() 大于 0 才表示修改成功

没有认真看手册吧。
http://www.w3school.com.cn/php/func_mysql_query.asp

返回值

mysql_query() 仅对 SELECT,SHOW,EXPLAIN 或 DESCRIBE 语句返回一个资源标识符,如果查询执行不正确则返回 FALSE。

对于其它类型的 SQL 语句,mysql_query() 在执行成功时返回 TRUE,出错时返回 FALSE。

非 FALSE 的返回值意味着查询是合法的并能够被服务器执行。这并不说明任何有关影响到的或返回的行数。很有可能一条查询执行成功了但并未影响到或并未返回任何行。



检查是否影响到了行数,应该用mysql_affected_rows()函数来检查检测。
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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
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)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

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-

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

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

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.

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

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles