Zepo. Posted September 25, 2007 Share Posted September 25, 2007 I have a session value : $_SESSION['id'] And i want to do a database pull $notepad=mysql_query("SELECT notes FROM staff WHERE id='$_SESSION['id']'"); $notepad=mysql_fetch_array($notepad); Not sure how to get the session to work out in it... Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/ Share on other sites More sharing options...
marcus Posted September 25, 2007 Share Posted September 25, 2007 session_start(); //must be on every page you want the session to exist on $_SESSION['id'] = "define the session"; //run query Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354495 Share on other sites More sharing options...
Zepo. Posted September 25, 2007 Author Share Posted September 25, 2007 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. Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354496 Share on other sites More sharing options...
cooldude832 Posted September 25, 2007 Share Posted September 25, 2007 what is line 7? Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354499 Share on other sites More sharing options...
Zepo. Posted September 25, 2007 Author Share Posted September 25, 2007 $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!"; } ?> Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354500 Share on other sites More sharing options...
cooldude832 Posted September 25, 2007 Share Posted September 25, 2007 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!"; } ?> Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354501 Share on other sites More sharing options...
trq Posted September 25, 2007 Share Posted September 25, 2007 Change... mysql_query("SELECT notes FROM staff WHERE id='$_SESSION['name']'"); to.... $sql = "SELECT notes FROM staff WHERE id = '{$_SESSION['name']}'"; mysql_query($sql) or die(mysql_error() . "<br />" . $sql); Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354503 Share on other sites More sharing options...
Zepo. Posted September 25, 2007 Author Share Posted September 25, 2007 Hmm, no errors, but the notes arnt displaying... Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354504 Share on other sites More sharing options...
marcus Posted September 25, 2007 Share Posted September 25, 2007 $notes isn't defined. I'm guessing you might want to add this somewheres: $row = mysql_fetch_assoc($res); //assuming $res = query thorpe posted $notes = $row['notes']; Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354505 Share on other sites More sharing options...
trq Posted September 25, 2007 Share Posted September 25, 2007 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354506 Share on other sites More sharing options...
Zepo. Posted September 25, 2007 Author Share Posted September 25, 2007 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/zepo/public_html/devlopment/admincp/includes/notepad.php on line 9 I changed res to sql and tired it and same error. Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354507 Share on other sites More sharing options...
trq Posted September 25, 2007 Share Posted September 25, 2007 Post your current code. Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354508 Share on other sites More sharing options...
Zepo. Posted September 25, 2007 Author Share Posted September 25, 2007 Got it nvm thanks. Link to comment https://forums.phpfreaks.com/topic/70551-solved-simple-session-question/#findComment-354509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.