henrikb Posted March 6, 2007 Share Posted March 6, 2007 Hi friends, Newbie question, if in the wrong place pleasemove the thread.. Please see code below, the highlighted code is what is not working. when I call $tb_stat I get "ACTIVE FREE Member" even if cStatus is "p". I am missing something here, please help! $con = db_connect(); if ($_GET["userid"]!="" && ($_GET["userid"]!=$_SESSION["nexus_userid"])){ $sql = "UPDATE nexus_users SET nViews=nViews+1 WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); } if ($nUserId->cStatus==p) {$tb_stat="Active PRO Member";} else $tb_stat="ACTIVE FREE Member"; Thanks in advance, Henrik Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted March 6, 2007 Share Posted March 6, 2007 try putting the p in quotation marks (") if ($nUserId->cStatus == "p"){ $tb_stat="Active PRO Member"; }else{ $tb_stat="ACTIVE FREE Member"; } echo $tb_stat; Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Hi, Thanks for your swift reply. Nope, still coming out as "ACTIVE FREE Member" where cStatus is 'p' Henrik Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted March 6, 2007 Share Posted March 6, 2007 echo out cStatus. echo $nUserId->cStatus; just to be sure it is equal to p. double check everything. Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Hi again, Not working, I tried: if ($nUserId->cStatus == ""){ $tb_stat="Active PRO Member"; }else{ $tb_stat="ACTIVE FREE Member"; } echo $tb_stat; leaving the "" emply and then it comes with "Active PRO Member" so it looks like it is not getting cStatus value from the database at all, maybe its because $sql = "SELECT * FROM nexus_users WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); is not getting the required values... Thanks again! Henrik Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 6, 2007 Share Posted March 6, 2007 Try putting: $userid=$_GET['userid']; Before the query. Then use $userid in the query. Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Hi, Is this correct: $con = db_connect(); $sql = "SELECT * FROM nexus_users WHERE $userid=".$_GET["userid"]; $result = mysql_query($sql,$con); if ($userid->cStatus == "p"){ $tb_stat="Active PRO Member"; }else{ $tb_stat="ACTIVE FREE Member"; } echo $tb_stat; This is is producing "ACTIVE FREE Member" Thanks, Henrik PS. Checked the database: where nUserId=1 cStatus is "p" Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 6, 2007 Share Posted March 6, 2007 $userid = $_GET['id']; $con = db_connect(); $sql = "SELECT * FROM nexus_users WHERE userid = '$userid'; $result = mysql_query($sql,$con); $row = mysql_fetch_array($result); $cStatus = $row['cStatus']; if ($cStatus == "p"){ $tb_stat="Active PRO Member"; }else{ $tb_stat="ACTIVE FREE Member"; } echo $tb_stat; This is how I would do it providing you are not posting the information to this page. If the userid gets posted to here from a form then it's a different story. This is also assuming that cStatus is in the db. Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Hi, This is the page members are coming to when they successfully have logged in http://www.xxxxx.com/xxxx.php?userid=1 The following code is getting the user ID and updating last time the user logged in etc. $con = db_connect(); if ($_GET["userid"]!="" && ($_GET["userid"]!=$_SESSION["nexus_userid"])){ $sql = "UPDATE nexus_users SET nViews=nViews+1 WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); } $sql = "SELECT * FROM nexus_users WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); What I am trying to do is have links on this page being active or inactive depending on if the member is a free member or paid member, using the "p" or "f" in the cStatus field in the database to determine what links are active/inactive... Sorry if this explanation is of little value but I hope it makes it easier to understand what I try to accomplish. Thanks in advance, Henrik Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 6, 2007 Share Posted March 6, 2007 You could do this with php but considering all the links on that page you might be better off trying to get a javascript that makes all links active or inactive depending on user status. Why not just send paid members to a different page. If user id matches database include("page2.php") or if userid doesn't match db include("page3.php"); which you could just copy and paste the other page and disable the links. Would probably be faster. Plus you could add another statement as to why they should join. Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Hi, Yes, I have to consider that option if I cannot get it to work right. Thanks for trying! Henrik Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 You need to put some debugging and error checking code into your script. <?php $con = db_connect(); if ($_GET["userid"]!="" && ($_GET["userid"]!=$_SESSION["nexus_userid"])){ $sql = "UPDATE nexus_users SET nViews=nViews+1 WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql) or die("Problem with Update Query:<pre>$sql</pre><br>" . mysql_error()); } $sql = "SELECT * FROM nexus_users WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql) or die("Problem with Select Query:<pre>$sql</pre><br>" . mysql_error()); $row = mysql_fetch_assoc($result); echo '<pre>' . print_r($row,true) . '</pre>'; // debugging line ?> Also, remember to put all of your code between tags when posting it. Ken Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Thanks Ken, I did a test script with your code and when called for member no 1. it produces: Array ( [nUserId] => 1 [cStatus] => p ) I keep on trying, there must be a way.... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 Can you repost the code that's not working? Remember to surround it with tags. Ken Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Ken, The first part that is working fine, the second part is the original code which I did myself which is not working.. Thanks, Henrik $con = db_connect(); if ($_GET["userid"]!="" && ($_GET["userid"]!=$_SESSION["nexus_userid"])){ $sql = "UPDATE nexus_users SET nViews=nViews+1 WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); } $sql = "SELECT * FROM nexus_users WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); if ($nUserId->cStatus==p) {$tb_stat="Active PRO Member";} else $tb_stat="ACTIVE FREE Member"; echo $tb_stat; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 The function mysql_query() only returns a pointer to the selected records, not the records themselves. To get the records, you need to use one of the mysql fetch function. My personal preference is mysql_fetch_assoc(). It this code snippet: <?php if ($nUserId->cStatus==p) {$tb_stat="Active PRO Member";} else $tb_stat="ACTIVE FREE Member"; echo $tb_stat; ?> where is "$nUserId->cStatus" coming from? I don't see it being set anywhere. Also, you should always enclose all literal strings in quotes. The "if" statement should read: <?php if ($nUserId->cStatus == 'p') $tb_stat="Active PRO Member"; else $tb_stat="ACTIVE FREE Member"; ?> Ken Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Hi, latest test.. <?php include "session.php"; include "config.php"; include "database.php"; $con = db_connect(); if ($_GET["userid"]!="" && ($_GET["userid"]!=$_SESSION["nexus_userid"])){ $sql = "UPDATE nexus_users SET nViews=nViews+1 WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); } $sql = "SELECT nUserId, cUsername, cStatus FROM nexus_users WHERE nUserId=".$_GET["userid"]; $result = mysql_query($sql,$con); $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["nUserId"] ; echo $row["cUsername"]; echo $row["cStatus"]; } if ($cStatus ='p'){ $tb_stat="Active PRO Member"; }else{ $tb_stat="ACTIVE FREE Member"; } mysql_free_result($result); echo $tb_stat; ?> Showing the following output for member 2 : 2 hboyander f Active PRO Member The 2 hboyander f is correct! but then it goes wrong again with Active PRO Member which should be ACTIVE FREE Member - I really dont get it... Anyway thanks for your constructive replies, Henrik Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 You either have to set "$cStatus" to $row['cStatus'] or use the array value directly in the "if" statement: <?php $cStatus = $row['cStatus']; if ($cStatus ='p'){ $tb_stat="Active PRO Member"; }else{ $tb_stat="ACTIVE FREE Member"; } ?> or <?php if ($row['cStatus'] ='p'){ $tb_stat="Active PRO Member"; }else{ $tb_stat="ACTIVE FREE Member"; } ?> Ken Quote Link to comment Share on other sites More sharing options...
henrikb Posted March 6, 2007 Author Share Posted March 6, 2007 Hi Ken, Did the changes but no improvement. Can you tell me why: ="p" comes out for all members as "Active PRO Member" =="p" comes out for all members as "Active Free Member" Thanks, Henrik Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 Sorry, use "==" for comparison, not "=". Ken 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.