Page 1 of 1

Where is the syntax error in this line?

Posted: Tue Sep 27, 2005 4:38 pm
by silverme
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I just started to learn PHP web and using dreamweaver mx. Mostly I use the applications in dreamweaver to help me write most of the php code. Now I tried to modify some code to get some results I want but I am stuck by this syntax error for a few hours and gave up figuring it out by myself...

$MM_Username is a session veriable.
Dreamweaver prompts there is a syntax error somewhere behind mi_ID =......(which is written by me. :( )

Code: Select all

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

Maybe it is easier for you to help me if I post the full code of this file. $MM_Username Have been given a value in a previous login page.

member.php

Code: Select all

<?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'] != "") {
    $FF_newQS = "?";
    reset ($HTTP_GET_VARS);
    while (list ($key, $val) = each ($HTTP_GET_VARS)) {
      if($key != "FF_Logoutnow"){
        if (strlen($FF_newQS) > 1) $FF_newQS .= "&";
        $FF_newQS .= $key . "=" . urlencode($val);
      }
    }
    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>&#26080;&#26631;&#39064;&#25991;&#26723;</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>
    <td width="157">Surname</td>
    <td width="146"><?php echo $row_logedMemRec['mi_surname']; ?></td>
  </tr>
  <tr>
    <td>Given Name </td>
    <td><?php echo $row_logedMemRec['mi_givenName']; ?></td>
  </tr>
  <tr>
    <td> </td>
    <td><?php echo $row_logedMemRec['mi_otherName']; ?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($logedMemRec);

mysql_free_result($logonMemRec);
?>
Thank You!


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Sep 27, 2005 6:09 pm
by feyd
mysql_fetch_row(mysql_query(SELECT lg_ID FROM logon WHERE lg_username='$MM_Username', $userLogon))

that's inside the string.. it can't be. MySQL has no internal functions by those names.

Posted: Tue Sep 27, 2005 6:33 pm
by silverme
So how should I change the code? All I need is to fetch the ID from the corresponding username. I don't get it. What does it mean "inside the string"?

Thanks

Posted: Tue Sep 27, 2005 6:55 pm
by feyd

Code: Select all

SELECT a.* FROM `memberinfo` a INNER JOIN `logon` b ON( a.`mi_ID` = b.`lg_ID` ) WHERE b.`lg_ssername` = '$MM_Username'

Posted: Tue Sep 27, 2005 7:40 pm
by Skara
mysql_fetch_row() and mysql_query() are php functions, not mysql. Using the querys you had, you would have to do the following:

Code: Select all

$result = mysql_query("SELECT lg_ID FROM logon WHERE lg_username='$MM_Username', $userLogon");
$row = mysql_fetch_row($result);
$query_logedMemRec = mysql_query("SELECT * FROM memberinfo WHERE mi_ID = $row[0]");
$finalrow = mysql_fetch_row($query_logedMemRec);
//$finalrow would equal an array, filled with all the info in `memberinfo`.
Using feyd's query (much better idea, obviously), you would need to do the following:

Code: Select all

$result = mysql_query("SELECT a.* FROM `memberinfo` a INNER JOIN `logon` b ON( a.`mi_ID` = b.`lg_ID` ) WHERE b.`lg_ssername` = '$MM_Username'");
$row = mysql_fetch_row($result);
//$row in this example is the same as $finalrow in the previous.