Jump to content

[SOLVED] Simple Session Question


Zepo.

Recommended Posts

The session start is there and the id is defined, but i get Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/zepo/public_html/devlopment/admincp/includes/notepad.php on line 7.

$notepad=mysql_query("SELECT notes FROM staff WHERE id='$_SESSION['id']'");

 

That line , the error basicly means that the session isnt showing up.

 

Heres the whole file:

 

<?
session_start(); 
if (isset($_SESSION['name'])) {
function notepad(){

mysql_query("SELECT notes FROM staff WHERE id='$_SESSION['name']'");

echo"
<body style='margin:0px'>
<div class='pagetitle'>Welcome Back!</div>
<div style='margin:10px'>

<br />
<form method='post'>
<table cellpadding='4' cellspacing='0' border='0' align='center' width='95%' class='tborder' id='optionsform'>
<colgroup span='2'>
<col style='width:45%'></col>
<col style='width:55%'></col>
</colgroup>
<tr>
<td class='tcat' align='center' colspan='2'>
<b>Admin CP Main</b>
</td>
</tr>
<tr valign='top'>
<td class='optiontitle'  colspan='2'><div>Notepad</div></td>
</tr>
<tbody id='tbody_keywords'>
<tr valign='top'>
<td class='alt1'><div class='smallfont' align='center'>
<textarea class='button' name='note' value='note' maxlength='600' style='width:950px; height:180px;'>$notes</textarea><BR />
<input type='hidden' name='act' value='notepad2'>
<input type='submit' name='submit' value='Update Notepad'></div>
</form></td>
</tr>
</tbody>
</table>";
}

function update($note){
echo"Updated";

}

}else{
echo"You are not logged in!";
}
?>

try this

<?php
session_start(); 
notepad();
function notepad(){
$q = "SELECT notes FROM staff WHERE id='".$_SESSION['name']."'";
mysql_query($q) or die(mysql_error());

echo"
<body style='margin:0px'>
<div class='pagetitle'>Welcome Back!</div>
<div style='margin:10px'>

<br />
<form method='post'>
<table cellpadding='4' cellspacing='0' border='0' align='center' width='95%' class='tborder' id='optionsform'>
<colgroup span='2'>
<col style='width:45%'></col>
<col style='width:55%'></col>
</colgroup>
<tr>
<td class='tcat' align='center' colspan='2'>
<b>Admin CP Main</b>
</td>
</tr>
<tr valign='top'>
<td class='optiontitle'  colspan='2'><div>Notepad</div></td>
</tr>
<tbody id='tbody_keywords'>
<tr valign='top'>
<td class='alt1'><div class='smallfont' align='center'>
<textarea class='button' name='note' value='note' maxlength='600' style='width:950px; height:180px;'>$notes</textarea><BR />
<input type='hidden' name='act' value='notepad2'>
<input type='submit' name='submit' value='Update Notepad'></div>
</form></td>
</tr>
</tbody>
</table>";
}

function update($note){
echo"Updated";

}

}else{
echo"You are not logged in!";
}
?>

Hmm, no errors, but the notes arnt displaying...

 

Because you never save (and later use) any result from your query. The general syntax for a select query should be something like...

 

<?php

 $sql = "SELECT fld FROM foo;";
 if ($result = mysql_query($sql)){
   if (mysql_num_rows($result)){
     while ($row = mysql_fetch_assoc($result)) {
       echo $row['fld'] . "<br />";
     }
   } else {
     echo "No results found";
   }
 } else {
   echo "Query failed<br />" . mysql_error() . "<br />$sql";
 }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.