把除了下面的代码之处的HTML标记全去掉 <?php $host="localhost"; $user="root"; $password=""; $dbname="info";mysql_connect("$host","$user","") or die("无法连接MySQL数据库服务器!"); $db=mysql_select_db("$dbname") or die("无法连接数据库!");$sql="select user_id from user where user_name='$user_name'"; $result=mysql_db_query("info",$sql); $num=mysql_num_rows($result); if($num<>0){ header("Location:reg.php?error=1");} else{ echo"检测通过!";} ?>
我只是照着书上做了一个简单的问候程序
之前一直是好着的,我刚换了PHP4.3.4,就出现上面的提示
会不会是我版本或配置的原因?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<form method="post" action="hello.php">
<input name="user_name" type="text" id="user_name" size="25" maxlength="16">
<?php
if($error=="1"){
echo "<font style='FONT-SIZE:16px' color='#FF0000'><b>";
echo "这个名字已经存在于数据库中了!";
echo "</b></font>";}
?>
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
hello.php
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<?php
$host="localhost";
$user="root";
$password="";
$dbname="info";mysql_connect("$host","$user","") or die("无法连接MySQL数据库服务器!");
$db=mysql_select_db("$dbname") or die("无法连接数据库!");$sql="select user_id from user where user_name='$user_name'";
$result=mysql_db_query("info",$sql);
$num=mysql_num_rows($result);
if($num<>0){
header("Location:reg.php?error=1");}
else{
echo"检测通过!";}
?>
</body>
</html>
可以参考一下.
<?php
$host="localhost";
$user="root";
$password="";
$dbname="info";mysql_connect("$host","$user","") or die("无法连接MySQL数据库服务器!");
$db=mysql_select_db("$dbname") or die("无法连接数据库!");$sql="select user_id from user where user_name='$user_name'";
$result=mysql_db_query("info",$sql);
$num=mysql_num_rows($result);
if($num<>0){
header("Location:reg.php?error=1");}
else{
echo"检测通过!";}
?>
header("Location:reg.php?error=1");}
else{
echo"检测通过!";}
在php程序中header不能有任何输入既包括html文档或者echo ,print等。这个转向你可以用javascript实现阿。
我是感觉那个header不太好用。
不是配置的问题,是我的代码写得不规范,换到最新的版本就出现问题了。看来我首先就是要解决我的编程习惯问题了。PS:sai1691(saihong) 我之前用的是4.3.2