无法连接到本地MySQL服务器

时间:2012-04-08 01:06:52

标签: php mysql

我的帐户页面配置如下;

if(!isset($_SESSION["myusername"])){ 
  

然后显示一些登录表单

否则连接到数据库并显示已记录用户的详细信息。页面显示表单,但底部有一些mysql错误。

Mysql error

问题是,此时条件只是显示表单,而不是连接到mysql。

现在输入用户名:demo@demo.com /密码:demo(字体为白色,我尚未修复。)网站为http://auto-sal.es/account.php

你会看到一切正常。 logged

任何人都可以帮我找出问题所在。

这是帐户页面的代码。

<?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>&nbsp;</td>
<td>&nbsp;</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');
?>

1 个答案:

答案 0 :(得分:2)

查看代码的这些行:

else
   include("conn.php");
$strSQL = "SELECT * FROM customer WHERE cus_id = '$cus_id';";
$rs = mysql_query($strSQL);

如果设置了$ _SESSION [“myusername”],您的代码将只包含连接文件(conn.php)。 您需要将所有查询代码包装在{ ... }

之间的else部分中