lobfredd Posted April 19, 2012 Share Posted April 19, 2012 Hello. I have a site with login function etc. Now i want a table displaying the records with the username same as the username logged in as. as you can see i have tried this: WHERE brukere.brukernavn ='$_SESSION['MM_Username']'"; but DW states syntax error. Is there an easy way to achieve what i am trying to do? I got the idea btw from this code: <?php if (!$_SESSION['MM_Username']) { echo "Welcome, {$_SESSION['MM_Username']}"; } ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2012 Share Posted April 19, 2012 Array variables that are inside of strings need to be surrounded with {} to tell php where they start and where they end (php cannot tell if $some_var['index'] means a scaler variable $some_var with the string ['index'] after it or you you meant an array variable $some_var['index'].) Quote Link to comment Share on other sites More sharing options...
lobfredd Posted April 19, 2012 Author Share Posted April 19, 2012 Thanks, that fixed the syntax error in the source code. However, the table do not display anything and when i press test under recordset in server behaviors i recieve an error aswell The error is: MySQL Error#:1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MM_Username']}'" at line 1 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2012 Share Posted April 19, 2012 Without the code for the whole query statement, it's not possible to tell you exactly why mysql found a syntax error at that point. The only thing I can tell from what you posted is that php couldn't find a valid php variable since it didn't replace it with its value and left the name of the variable in the resulting string. Quote Link to comment Share on other sites More sharing options...
lobfredd Posted April 19, 2012 Author Share Posted April 19, 2012 This is the code DW has filled out before everything: <?php require_once('Connections/lol.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_test = 10; $pageNum_test = 0; if (isset($_GET['pageNum_test'])) { $pageNum_test = $_GET['pageNum_test']; } $startRow_test = $pageNum_test * $maxRows_test; mysql_select_db($database_lol, $lol); $query_test = "SELECT * FROM brukere WHERE brukere.brukernavn ='{$_SESSION['MM_Username']}'"; $query_limit_test = sprintf("%s LIMIT %d, %d", $query_test, $startRow_test, $maxRows_test); $test = mysql_query($query_limit_test, $lol) or die(mysql_error()); $row_test = mysql_fetch_assoc($test); if (isset($_GET['totalRows_test'])) { $totalRows_test = $_GET['totalRows_test']; } else { $all_test = mysql_query($query_test); $totalRows_test = mysql_num_rows($all_test); } $totalPages_test = ceil($totalRows_test/$maxRows_test)-1; ?> And this is the table in the body tag <table border="1"> <tr> <td>access</td> <td>brukernavn</td> <td>passord</td> <td>email</td> <td>navn</td> <td>etternavn</td> <td>adresse</td> <td>postnummer</td> <td>poststed</td> </tr> <?php do { ?> <tr> <td><?php echo $row_test['access']; ?></td> <td><?php echo $row_test['brukernavn']; ?></td> <td><?php echo $row_test['passord']; ?></td> <td><?php echo $row_test['email']; ?></td> <td><?php echo $row_test['navn']; ?></td> <td><?php echo $row_test['etternavn']; ?></td> <td><?php echo $row_test['adresse']; ?></td> <td><?php echo $row_test['postnummer']; ?></td> <td><?php echo $row_test['poststed']; ?></td> </tr> <?php } while ($row_test = mysql_fetch_assoc($test)); ?> </table> Quote Link to comment Share on other sites More sharing options...
lobfredd Posted April 19, 2012 Author Share Posted April 19, 2012 This is the code DW has filled out before everything: <?php require_once('Connections/lol.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_test = 10; $pageNum_test = 0; if (isset($_GET['pageNum_test'])) { $pageNum_test = $_GET['pageNum_test']; } $startRow_test = $pageNum_test * $maxRows_test; mysql_select_db($database_lol, $lol); $query_test = "SELECT * FROM brukere WHERE brukere.brukernavn ='{$_SESSION['MM_Username']}'"; $query_limit_test = sprintf("%s LIMIT %d, %d", $query_test, $startRow_test, $maxRows_test); $test = mysql_query($query_limit_test, $lol) or die(mysql_error()); $row_test = mysql_fetch_assoc($test); if (isset($_GET['totalRows_test'])) { $totalRows_test = $_GET['totalRows_test']; } else { $all_test = mysql_query($query_test); $totalRows_test = mysql_num_rows($all_test); } $totalPages_test = ceil($totalRows_test/$maxRows_test)-1; ?> And this is the table in the body tag <table border="1"> <tr> <td>access</td> <td>brukernavn</td> <td>passord</td> <td>email</td> <td>navn</td> <td>etternavn</td> <td>adresse</td> <td>postnummer</td> <td>poststed</td> </tr> <?php do { ?> <tr> <td><?php echo $row_test['access']; ?></td> <td><?php echo $row_test['brukernavn']; ?></td> <td><?php echo $row_test['passord']; ?></td> <td><?php echo $row_test['email']; ?></td> <td><?php echo $row_test['navn']; ?></td> <td><?php echo $row_test['etternavn']; ?></td> <td><?php echo $row_test['adresse']; ?></td> <td><?php echo $row_test['postnummer']; ?></td> <td><?php echo $row_test['poststed']; ?></td> </tr> <?php } while ($row_test = mysql_fetch_assoc($test)); ?> </table> ah, just solved it by putting session start before everything. Many Thanks for ur help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.