Jump to content

Can someone explain the meaning of these lines?


thewhat

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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. :P Gotta figure out where it's not connecting. Thanks much!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.