各位朋友:这段代码是“查询密码第一步:输入会员名”,想实现的效果:当名字在数据库中不存在时,转到错误页面。
我这个代码老是出现:Warning: Cannot modify header information - headers already sent by (output started at F:\PHPSites\member\getpwd1-1.php:23) in F:\PHPSites\member\getpwd1-1.php on line 36
应该怎么改呢?非常感谢了!
<?php$totalRows_rsMember = 0;?><?php require_once('Connections/member.php'); ?><?php$colname_rsMember = "-1";if (isset($_POST['txtusername'])) { $colname_rsMember = (get_magic_quotes_gpc()) ? $_POST['txtusername'] : addslashes($_POST['txtusername']);}mysql_select_db($database_member, $member);$query_rsMember = sprintf("SELECT username FROM members WHERE username = '%s'", $colname_rsMember);$rsMember = mysql_query($query_rsMember, $member) or die(mysql_error());$row_rsMember = mysql_fetch_assoc($rsMember);$totalRows_rsMember = mysql_num_rows($rsMember);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><link href="style/style.css" rel="stylesheet" type="text/css" /><script language="javascript">function checkFormData () { if ( form1.txtUsername.value == "" ) { alert ( "用户名不能为空,请重新输入!" ); form1.txtUsername.focus(); return false; }}</script></head><body><?php include('menu.php'); ?><?phpif ($totalRows_rsMember == 0) { header ( "Location: message-1.php?error=3" ); exit;}?><form action="getpwd2-1.php" method="post" name="form1" id="form1" onsubmit="return checkFormData()"> <table width="256" border="1" align="center" rules="none"> <tr> <th colspan="2" bgcolor="#0066CC" class="title">第一步:输入会员名</th> </tr> <tr> <td width="72" height="32" align="right">用户名:</td> <td width="168" height="32"><input name="txtUsername" type="text" id="txtUsername" /></td> </tr> <tr> <td height="32" colspan="2" align="center"><input name="btnNext" type="submit" id="btnNext" value="下一步" /></td> </tr> </table></form></body></html><?phpmysql_free_result($rsMember);?>
回复讨论(解决方案)
在 getpwd1-1.php 的 23 行处有输出
导致 header ( "Location: message-1.php?error=3" ); 出错
先检查那个输出是否确实必要?是否能调整到别处
实在不行的话,可在 require_once('Connections/member.php'); 前加上
ob_start();
来回避
在 getpwd1-1.php 的 23 行处有输出
导致 header ( "Location: message-1.php?error=3" ); 出错
先检查那个输出是否确实必要?是否能调整到别处
实在不行的话,可在 require_once('Connections/member.php'); 前加上
ob_start();
来回避
……
版主大人:我贴上来的就是getpwd1-1.php中的所有代码,具体要怎么调整?
如果在 require_once('Connections/member.php'); 前加上ob_start();的话,就直接转到错误页面了,而不是“输入不存在的用户名再转到错误页面”了。请指点,非常感谢!
粗心了没核实文件名
把 16 到 33 行(含33行)的内容移到 39 行的后面
另外 10 到 14 行的内容应当在 7 行的条件分支里
粗心了没核实文件名
把 16 到 33 行(含33行)的内容移到 39 行的后面
另外 10 到 14 行的内容应当在 7 行的条件分支里
版主大人:我照着您指点的改了,如下,但还是直接就转到错误页面啊!
<?php$totalRows_rsMember = 0;?><?php require_once('Connections/member.php'); ?><?php$colname_rsMember = "-1";if (isset($_POST['txtusername'])) { $colname_rsMember = (get_magic_quotes_gpc()) ? $_POST['txtusername'] : addslashes($_POST['txtusername']); mysql_select_db($database_member, $member);$query_rsMember = sprintf("SELECT username FROM members WHERE username = '%s'", $colname_rsMember);$rsMember = mysql_query($query_rsMember, $member) or die(mysql_error());$row_rsMember = mysql_fetch_assoc($rsMember);$totalRows_rsMember = mysql_num_rows($rsMember);}?><?phpif ($totalRows_rsMember == 0) { header ( "Location: message-1.php?error=3" ); exit;}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><link href="style/style.css" rel="stylesheet" type="text/css" /><script language="javascript">function checkFormData () { if ( form1.txtUsername.value == "" ) { alert ( "用户名不能为空,请重新输入!" ); form1.txtUsername.focus(); return false; }}</script></head><body><?php include('menu.php'); ?><form action="getpwd2-1.php" method="post" name="form1" id="form1" onsubmit="return checkFormData()"> <table width="256" border="1" align="center" rules="none"> <tr> <th colspan="2" bgcolor="#0066CC" class="title">第一步:输入会员名</th> </tr> <tr> <td width="72" height="32" align="right">用户名:</td> <td width="168" height="32"><input name="txtUsername" type="text" id="txtUsername" /></td> </tr> <tr> <td height="32" colspan="2" align="center"><input name="btnNext" type="submit" id="btnNext" value="下一步" /></td> </tr> </table></form></body></html><?phpmysql_free_result($rsMember);?>
5 到 21 行改成
<?php$colname_rsMember = "-1";if (isset($_POST['txtusername'])) { $colname_rsMember = (get_magic_quotes_gpc()) ? $_POST['txtusername'] : addslashes($_POST['txtusername']); mysql_select_db($database_member, $member); $query_rsMember = sprintf("SELECT username FROM members WHERE username = '%s'", $colname_rsMember); $rsMember = mysql_query($query_rsMember, $member) or die(mysql_error()); $row_rsMember = mysql_fetch_assoc($rsMember); $totalRows_rsMember = mysql_num_rows($rsMember); if ($totalRows_rsMember == 0) { header ( "Location: message-1.php?error=3" ); exit; }}?>自己想一下,问什么要这样写?
5 到 21 行改成
PHP code?123456789101112131415
原来可以这样,终于把这个逻辑理清楚了,多谢版主大人!

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.

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

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

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

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

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


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool