我有一个配置如下的帐户页面;
if(!isset($_SESSION["myusername"])){
然后显示一些登录表单
否则连接到数据库并显示登录用户的详细信息。该页面显示表单,但底部有一些 mysql 错误。
问题是此时条件只是显示表单,而不是连接到 mysql。
现在输入用户名:demo@demo.com / 密码:demo(字体是白色的,我还没有修复。)网站是http://auto-sal.es/account.php
你会看到一切正常。
谁能帮我找出问题所在。
这是帐户页面的代码。
<?php include("header.php"); ?>
<body id="account">
<div id="wholewrap">
<div id="bodywrap">
<div id="content">
<?php
session_start();
if(!isset($_SESSION["myusername"])){
$form = '
<h1>Members section</h1>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>';
echo $form;
}
else
include("conn.php");
$strSQL = "SELECT * FROM customer WHERE cus_id = '$cus_id';";
$rs = mysql_query($strSQL);
mysql_error();
while($row = mysql_fetch_array($rs)) {
$layout='
<h1>Your details</h1>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="308" valign="top"><p>Name:</p></td>
<td width="308" valign="top"><p>' . $row['name'] . '</p></td>
</tr>
<tr>
<td width="308" valign="top"><p>DOB:</p></td>
<td width="308" valign="top"><p>' . $row['dob'] . '</p></td>
</tr>
<tr>
<td width="308" valign="top"><p>Address:</p></td>
<td width="308" valign="top"><p>' . $row['address'] . '</p></td>
</tr>
<tr>
<td width="308" valign="top"><p>Email:</p></td>
<td width="308" valign="top"><p>' . $row['email'] . '</p></td>
</tr>
<tr>
<td width="308" valign="top"><p>Telephone:</p></td>
<td width="308" valign="top"><p>' . $row['telephone'] . '</p></td>
</tr>
<tr>
<td width="308" valign="top"><p>Join date:</p></td>
<td width="308" valign="top"><p>' . $row['join_date'] . '</p></td>
</tr>
<tr>
<td width="308" valign="top"><p>Last access:</p></td>
<td width="308" valign="top"><p>' . $row['last_access'] . '</p></td>
</tr>
</table>';
echo $layout;
}
mysql_close();
?>
</div> <!-- content #end -->
<div id="sidebar">
<h1>Sidebar</h1>
</div> <!-- sidebar #end -->
</div> <!-- bodywrap #end -->
</div> <!-- wholewrap #end -->
<?php include("footer.php");?>
连接内容
<?php
$host="xxx"; // Host name
$username="xxxx"; // Mysql username
$password="xxx"; // Mysql password
$db_name="xxx"; // Database name
$name=$_SESSION['name'];
$cus_id=$_SESSION['cus_id'];
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
mysql_set_charset('utf8');
?>