thewhat Posted December 17, 2007 Share Posted December 17, 2007 hi all. I'm working with this pre-made CMS and on a certain page these lines are included. Now the page where they're originally included works just fine. However, when I try to copy and paste the code into another page is when it starts screwing up. I've narrowed it down to this area, because it always redirects to anything I put there. if (!isset($group_id)) { if (!isset($lookup) || !isNum($lookup)) fallback("index.php"); $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_id='$lookup'"); if (dbrows($result)) { $data = dbarray($result); } else { redirect("index.php"); } So can anyone help me out? If there's any other part of the code that is needed to explain, let me know. But I think it's pretty understandable from here. If not let me know. Thanks in advanced. Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted December 17, 2007 Share Posted December 17, 2007 line to means that if $lookup has no value or non-numeric it will redirect to index.php Quote Link to comment Share on other sites More sharing options...
thewhat Posted December 17, 2007 Author Share Posted December 17, 2007 but it does have a value. It calls directly from the user_id table which are all numbers. ??? Quote Link to comment Share on other sites More sharing options...
btherl Posted December 17, 2007 Share Posted December 17, 2007 I don't understand your last sentence there. Perhaps your code is not setting $lookup, but the place where you cut and paste from IS setting $lookup? You can try printout out the value and then terminating the script with exit(). The reason for terminating is so you don't get redirected and lose your output. Quote Link to comment Share on other sites More sharing options...
thewhat Posted December 17, 2007 Author Share Posted December 17, 2007 I don't understand your last sentence there. Perhaps your code is not setting $lookup, but the place where you cut and paste from IS setting $lookup? You can try printout out the value and then terminating the script with exit(). The reason for terminating is so you don't get redirected and lose your output. Well why wouldn't the two pages work? It's the same thing. Also, can you elaborate on the printing out part? I'd like to try this. Quote Link to comment Share on other sites More sharing options...
btherl Posted December 17, 2007 Share Posted December 17, 2007 The code you posted uses the variables $group_id, $lookup and $db_prefix. If these variables are not set, or have different values, then the code will behave differently. So this could be why the same code acts differently when used in different places. Here's how you would do the printing check: if (!isset($group_id)) { print "group_id not set. Entering redirect check with lookup = $lookup, db_prefix = $db_prefix";exit(0); if (!isset($lookup) || !isNum($lookup)) fallback("index.php"); $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_id='$lookup'"); if (dbrows($result)) { $data = dbarray($result); } else { redirect("index.php"); } What that will do is tell you what $lookup and $db_prefix are set to when that code is entered. After observing the values, you can delete that line and continue debugging. I use this method hundreds of times daily while developing code. The reason for the exit(0) is that a 302 redirect will prevent you from seeing the output of the print statement (that is, if the script is doing a 302 redirect. If it isn't, then you don't need to exit) Quote Link to comment Share on other sites More sharing options...
thewhat Posted December 17, 2007 Author Share Posted December 17, 2007 Hmm, alright I tried it. On both the page I'm copying it from and my custom page. On the page I copy from $lookup = has an answer but on the page I paste to, it does not. So I'm narrowing down my problems. Gotta figure out where it's not connecting. Thanks much! Quote Link to comment Share on other sites More sharing options...
thewhat Posted December 17, 2007 Author Share Posted December 17, 2007 Its this damn query that doesn't go through when you copy and paste. $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_id='$lookup'"); WTF Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 Where are $lookup and $db_prefix defined? Quote Link to comment Share on other sites More sharing options...
thewhat Posted December 17, 2007 Author Share Posted December 17, 2007 I thought $lookup was defined in that query. $db_prefix is defined in config.php, which maincore.php includes. Everything in that code works when it isn't copy/pasted. That's the only issue. :-\ Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 17, 2007 Share Posted December 17, 2007 When creating custom pages to work with a 3rd party CMS, you have to remember to include all relevant scripts, and if creating functions, bring in the global values. So, in your page, are you including maincore.php? It probably includes config.php etc... at any rate, initializing a custom page to use everything available to the CMS is a trial and error process... we can only guess at this point. What is the CMS btw? PhREEEk Quote Link to comment Share on other sites More sharing options...
thewhat Posted December 18, 2007 Author Share Posted December 18, 2007 It's PHPFusion. You may or may not be familiar with. But I'm telling you, I copied/pasted the entire script(even the disclaimers, lol)and the DB wasn't called for $lookup. No changes made. Nothing. Quote Link to comment Share on other sites More sharing options...
thewhat Posted December 18, 2007 Author Share Posted December 18, 2007 Well I didn't find where $lookup's problem is but I did find where the user's data is stored in a variable. So either way, I got what I wanted. I can just do this now: echo $userdata['user_id']; and it works. Thanks for the help anyway, guys. 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.