回 帖 发 新 帖 刷新版面

主题:请问这句php的语法错在哪里?谢谢

开始学做一个PHP网页,用DreamWeaver做。在这一句尝试自己写,然后DW说我mysql_query后面有语法错误,但我就是看了几个小时就想不通,为这一句呆了好久(可能以后还有很多句。。。困难重重),请各位指点一下。  $MM_Username是一个session变量。

[code]
$query_logedMemRec = "SELECT * FROM memberinfo WHERE mi_ID = mysql_fetch_row(mysql_query(SELECT lg_ID FROM logon WHERE lg_username='$MM_Username', $userLogon))";
[/code]


还是附全文好了。$MM_Username 已经在前一个登陆界面赋值。
member.php
[code]
<?php require_once('Connections/userLogon.php'); ?>
<?php
session_start(); //added
// *** Logout the current user.
$FF_Logout = $HTTP_SERVER_VARS['PHP_SELF'] . "?FF_Logoutnow=1";
if (isset($HTTP_GET_VARS['FF_Logoutnow']) && $HTTP_GET_VARS['FF_Logoutnow']=="1") {
  session_start();
  session_unregister("MM_Username");
  session_unregister("MM_UserAuthorization");
  $FF_logoutRedirectPage = "logon.php";
  // redirect with URL parameters (remove the "FF_Logoutnow" query param).
  if ($FF_logoutRedirectPage == "") $FF_logoutRedirectPage = $HTTP_SERVER_VARS['PHP_SELF'];
  if (!strpos($FF_logoutRedirectPage, "?") && $HTTP_SERVER_VARS['QUERY_STRING'] != "") {
&#160;  $FF_newQS = "?";
&#160;  reset ($HTTP_GET_VARS);
&#160;  while (list ($key, $val) = each ($HTTP_GET_VARS)) {
&#160;  &#160; if($key != "FF_Logoutnow"){
&#160;  &#160; &#160; if (strlen($FF_newQS) > 1) $FF_newQS .= "&";
&#160;  &#160; &#160; $FF_newQS .= $key . "=" . urlencode($val);
&#160;  &#160; }
&#160;  }
&#160;  if (strlen($FF_newQS) > 1) $FF_logoutRedirectPage .= $FF_newQS;
  }
  header("Location: $FF_logoutRedirectPage");
  exit;
}

mysql_select_db($database_userLogon, $userLogon);
$query_logedMemRec = "SELECT * FROM memberinfo WHERE mi_ID = mysql_fetch_row(mysql_query(SELECT lg_ID FROM logon WHERE lg_username='$MM_Username', $userLogon))";  #problem !
$logedMemRec = mysql_query($query_logedMemRec, $userLogon) or die(mysql_error());
$row_logedMemRec = mysql_fetch_assoc($logedMemRec);
$totalRows_logedMemRec = mysql_num_rows($logedMemRec);

$colname_logonMemRec = "1";
if (isset($_SESSION['MM_Username'])) {
  $colname_logonMemRec = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_userLogon, $userLogon);
$query_logonMemRec = sprintf("SELECT * FROM logon WHERE lg_username = '%s'", $colname_logonMemRec);
$logonMemRec = mysql_query($query_logonMemRec, $userLogon) or die(mysql_error());
$row_logonMemRec = mysql_fetch_assoc($logonMemRec);
$totalRows_logonMemRec = mysql_num_rows($logonMemRec);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[url]http://www.w3.org/TR/html4/loose.dtd[/url]">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<p>Log on Secceed. This is a member page. <a href="<?php echo $FF_Logout ?>">Log out</a> </p>
<p>  </p>
<table width="307" border="0" cellspacing="0">
  <tr>
&#160;  <td width="157">Surname</td>
&#160;  <td width="146"><?php echo $row_logedMemRec['mi_surname']; ?></td>
  </tr>
  <tr>
&#160;  <td>Given Name </td>
&#160;  <td><?php echo $row_logedMemRec['mi_givenName']; ?></td>
  </tr>
  <tr>
&#160;  <td> </td>
&#160;  <td><?php echo $row_logedMemRec['mi_otherName']; ?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($logedMemRec);

mysql_free_result($logonMemRec);
?>
[/code]

回复列表 (共1个回复)

沙发

$query_logedMemRec = "SELECT * FROM memberinfo WHERE mi_ID = mysql_fetch_row(mysql_query(SELECT lg_ID FROM logon WHERE lg_username='$MM_Username', $userLogon))";

你的sql语句有问题啊。
mysql_fetch_row 函数返回数组变量。把其中的变量赋值后在进行传递。
把上面的sql语句分开写成三行试试。

我来回复

您尚未登录,请登录后再回复。点此登录或注册