stublackett Posted February 18, 2008 Share Posted February 18, 2008 Hi, I'm trying to show a HEREDOC to match user settings, But its not outputting the relevant HEREDOC Command Anyone know what needs to be altered to make it show, The menu relevant to the user level? <?php session_start(); include ("dbconnect.php"); if(!isset($_SESSION[username])){ $message = <<<HTML This page is for Registered users only <br /> <br /> Register to the site, <br /> <br /> By following the link in the menu on the left HTML; }else{ //Protected Area sits below $message = "Welcome to the Dragons Den ".$_SESSION["username"]; } //Check users' User level (1 = Dragon) (2 = Entrepeneur) (3 = Admin) mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); $sql="SELECT * FROM $db_table WHERE username='" . mysql_real_escape_string($_SESSION[username]) . ""; $result = mysql_query ($sql); $username = $_SESSION['username'] ; $userlevel = $_SESSION['userlevel']; if($userlevel==1){ $usersettings = "1"; }else if($userlevel == 2){ $usersettings = "2"; } //If Userlevel is 1 show the Entrepeneurs' Form (On the left) if($usersettings==1){ //Entrepeneur List $entrepeneur = <<<LEFTSIDE <div id="login"> <b>Welcome to the site $username</b> <ul> <li>View Your Ideas </li> <li>View Your Offers</li> </ul> </div> LEFTSIDE; } //Otherwise show the Dragons' Form (On the left) else if($usersettings==2){ //Dragon List $dragon = <<<DRAGON <div id="dragon"> <b>Welcome to the site $username</b> <ul> <li>View Latest Ideas </li> <li>Make an Offer</li> <li>Review Offers </li> <li>View All Ideas</li> <li>Manage Your Profile</li> </ul> </div> DRAGON; } ?> Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 you could simplify your document a little by using $userlevel instead of setting $usersettings. the HEREDOC variables can should be called the same name to simplify the script also. is your session data storing the userlevel? or are you trying to find out the userlevel from mysql? if the latter is true then the following should fixthe problem? (i went at the liberty to clean the script, hope u dont mind:P ) <?php session_start(); include ("dbconnect.php"); if(!isset($_SESSION[username])){ $message = <<<HTML This page is for Registered users only <br /> <br /> Register to the site, <br /> <br /> By following the link in the menu on the left HTML; }else{ //Protected Area sits below $message = "Welcome to the Dragons Den ".$_SESSION["username"]; } //Check users' User level (1 = Dragon) (2 = Entrepeneur) (3 = Admin) mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); // changed * to `userlevel` to only get needed data (rather than username/id and userlevel in an array you get one string per array/row) $sql="SELECT `userlevel` FROM $db_table WHERE username='".mysql_real_escape_string($_SESSION[username]); $result = mysql_query($sql); $username = $_SESSION['username']; $userlevel = mysql_result($result,0); // gets userlevel from mysql result //If Userlevel is 1 show the Entrepeneurs' Form (On the left) if($userlevel=="1"){ //Entrepeneur List $page = <<<LEFTSIDE <div id="login"> <b>Welcome to the site $username</b> <ul> <li>View Your Ideas </li> <li>View Your Offers</li> </ul> </div> LEFTSIDE; } //Otherwise show the Dragons' Form (On the left) else if($userlevel=="2"){ //Dragon List $page = <<<DRAGON <div id="dragon"> <b>Welcome to the site $username</b> <ul> <li>View Latest Ideas </li> <li>Make an Offer</li> <li>Review Offers </li> <li>View All Ideas</li> <li>Manage Your Profile</li> </ul> </div> DRAGON; } echo($page); ?> Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 18, 2008 Author Share Posted February 18, 2008 Muchos Gracias! As the Spaniards say Codes following the principles I have and yes the Session ID of 1 or 2 is being output, I checked that with an echo statement BUT That SQL Statement is causing a bit of trouble Warning: Wrong parameter count for mysql_result() on line 27 Line 27 being the new SQL Select you put in for me $userlevel = mysql_result($result,0); // gets userlevel from mysql result Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 doesnt make sense, lol. could you add this before the erroring statement: print_r(mysql_fetch_array($result)); tell me what it say in the source code of the page Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 18, 2008 Author Share Posted February 18, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 27 Warning: mysql_result(): supplied argument is not a valid MySQL result resource on line 28 Thing is, Its already got the Userlevel selected, So maybe that code doesnt need to be used? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 what exactly are you pulling from the mysql database? if the userlevel is ONLY stored in mysql try this: <?php session_start(); include ("dbconnect.php"); if(!isset($_SESSION['username'])){ $message = <<<HTML This page is for Registered users only <br /> <br /> Register to the site, <br /> <br /> By following the link in the menu on the left HTML; }else{ //Protected Area sits below $message = "Welcome to the Dragons Den ".$_SESSION['username']; } //Check users' User level (1 = Dragon) (2 = Entrepeneur) (3 = Admin) mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); // changed * to `userlevel` to only get needed data (rather than username/id and userlevel in an array you get one string per array/row) $sql="SELECT `userlevel` FROM $db_table WHERE username='".mysql_real_escape_string($_SESSION['username']); $result = mysql_query($sql) or die("QUERY ERROR:<br>".mysql_error()); $username = $_SESSION['username']; $userlevel = mysql_result($result,0); //If Userlevel is 1 show the Entrepeneurs' Form (On the left) if($userlevel=="1"){ //Entrepeneur List $page = <<<LEFTSIDE <div id="login"> <b>Welcome to the site $username</b> <ul> <li>View Your Ideas </li> <li>View Your Offers</li> </ul> </div> LEFTSIDE; } //Otherwise show the Dragons' Form (On the left) else if($userlevel=="2"){ //Dragon List $page = <<<DRAGON <div id="dragon"> <b>Welcome to the site $username</b> <ul> <li>View Latest Ideas </li> <li>Make an Offer</li> <li>Review Offers </li> <li>View All Ideas</li> <li>Manage Your Profile</li> </ul> </div> DRAGON; } echo($page); ?> If userlevel is ALREADY stored in a SESSION variable this should work: <?php session_start(); include ("dbconnect.php"); if(!isset($_SESSION['username'])){ $message = <<<HTML This page is for Registered users only <br /> <br /> Register to the site, <br /> <br /> By following the link in the menu on the left HTML; }else{ //Protected Area sits below $message = "Welcome to the Dragons Den ".$_SESSION['username']; } $username = $_SESSION['username']; $userlevel = $_SESSION['userlevel']; //If Userlevel is 1 show the Entrepeneurs' Form (On the left) if($userlevel == "1"){ //Entrepeneur List $page = <<<LEFTSIDE <div id="login"> <b>Welcome to the site $username</b> <ul> <li>View Your Ideas </li> <li>View Your Offers</li> </ul> </div> LEFTSIDE; } //Otherwise show the Dragons' Form (On the left) else if($userlevel == "2"){ //Dragon List $page = <<<DRAGON <div id="dragon"> <b>Welcome to the site $username</b> <ul> <li>View Latest Ideas </li> <li>Make an Offer</li> <li>Review Offers </li> <li>View All Ideas</li> <li>Manage Your Profile</li> </ul> </div> DRAGON; } echo($page); ?> the last code removes the mysql query, since it serves no purpose if you already have the userlevel. Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 18, 2008 Author Share Posted February 18, 2008 Spot on! Thanks very much, That now works! 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.