丛书集成初编 中华:谁帮我看看php代码,谁会~~~

来源:百度文库 编辑:高校问答 时间:2024/04/28 22:11:41
问一下,我做的会员注册页编码如下:
<?php
//初始化session
session_start();
// 包含数据库连接文件和头文件
require ('dbconnect.php');
include('head.php');
?>
<?
if(!isset($_SESSION['username'])) {
echo "<p align=center>";
echo "<font color=#FF0000 size=5><strong><big>";
echo "对不起,您无权查看此页!";
echo "</big></strong></font></p>";
exit();
}
$id=$_GET['id'];
echo "<table align=center><tr><td ><font color=red>注册成功!</font></td></tr>";
echo "<tr><td >下面是你的注册资料:</td></tr>";
// 取得注册资料
$sql="select * from yhzc where id='$id'";
$re=mysql_query($sql,$conn);
$result=mysql_fetch_array($re);
?>
<tr>
<td>用户名:</td>
<td>
<?echo $result[ID];?></td>
</tr>
<tr>
<td>真实姓名:</td>
<td>
<?echo $result[name];?></td>
</tr>
<tr>
<td>性别:</td>
<td>
<?echo $result[sex];?></td>
</tr>
<tr>
<td>种类:</td>
<td>
<?echo $result[kind];?></td>
</tr>
<tr>
<td>部门:</td>
<td>
<?echo $result[DP];?></td>
</tr>
<tr>
<td>Email:</td>
<td>
<?echo $result[email];?></td>
</tr>
<tr>
<td>城市:</td>
<td>
<?echo $result[city];?>
</td>
</tr>

<tr>
<td>电话:</td>
<td>
<?echo $result[tel];?>
</td>
</tr>

<?

// 如果登录了,注销登录
if(isset($_SESSION['username'])) {
session_unset();
session_destroy();
}
?>
</table>

填完后确定有如下问题:

注册成功!
下面是你的注册资料:
用户名:
Notice: Use of undefined constant ID - assumed 'ID' in C:\Inetpub\wwwroot\bysj\regok.php on line 27

真实姓名:
Notice: Use of undefined constant name - assumed 'name' in C:\Inetpub\wwwroot\bysj\regok.php on line 32

性别:
Notice: Use of undefined constant sex - assumed 'sex' in C:\Inetpub\wwwroot\bysj\regok.php on line 37

种类:
Notice: Use of undefined constant kind - assumed 'kind' in C:\Inetpub\wwwroot\bysj\regok.php on line 42

部门:
Notice: Use of undefined constant DP - assumed 'DP' in C:\Inetpub\wwwroot\bysj\regok.php on line 47

Email:
Notice: Use of undefined constant email - assumed 'email' in C:\Inetpub\wwwroot\bysj\regok.php on line 52

城市:
Notice: Use of undefined constant city - assumed 'city' in C:\Inetpub\wwwroot\bysj\regok.php on line 57

电话:
Notice: Use of undefined constant tel - assumed 'tel' in C:\Inetpub\wwwroot\bysj\regok.php on line 65

因为你的php.ini中配置的是
error_reporting = E_ALL
这样php对变量的检测比较严格。使用变量之前要先声明。。

你可以打开php.ini将其改为
error_reporting = E_ALL & ~E_NOTICE
重启apache或iis
这样就可以将你的警告提示去掉了。