Jump to content

Recommended Posts

Posted

I built a basic content management system in php using mysql. I have it up and running fine on a local test server, using php 4.3.3 and the current build of mysql. When I tried to post it to my TCH account, I'm getting some odd results.

 

Here is the first section of the code:

 

>echo("The request var for page is {$_REQUEST['page']}<br>");	//debugging code

// Checks to see whether the requested page exists and sets a default page if it doesn't.
if ( isset($_REQUEST['page']) )
{
$page->name = $_REQUEST['page'];
 echo("Requested page is $page->name");	// debugging code
if (!entry_exists('pagedata','name',$page->name))
{
 $page->name = "404";	// File Not Found Error Page
}
}
else
{
$page->name = "home";
}

 

The _REQUEST var is set properly. But $page->name (as well as any other variables that use object syntax) is null, which naturally breaks the rest of the code.

 

The thing that makes this perplexing is that I have a completely different script that opens the exact same way, and it appears to be functioning properly. I even wrote a basic test script that just assigns and echoes $page->name and it works fine. All the code runs happily on my test server.

 

I've tried re-ftp'ing the files to the host numerous times. I even tried to upload the content to another host as a test with the same results. So I'm pretty stumped as to what the problem could be, and why it works in one script but won't in another.

 

Any ideas would be greatly appreciated. Thanks!

 

Cheers,

 

Chris

Posted

I'm not much of an OOP code writer, but shouldn't you have code like

 

$page = new Whatever;

 

That's the best I've got. Hope it helps.

Posted

Well, I'd say the same as Jack: have you created an instance of an object (which contains a $name member variable) named $page?

 

Perhaps you forgot to include the file that defines the $page class?

 

Another suggestion I'd make is to use $_GET instead of $_REQUEST. I see lots of people using $_REQUEST but I really don't understand why.

$_REQUEST has $_GET, $_POST and $_COOKIES all mixed in the same array, which, in my humble opinion, can be quite a mess.

I prefer to diferentiate them by using the different variables for each of them.

Posted

Thanks for the responses guys. I appreciate the feedback.

 

I had wondered whether objects and array variables could be defined on the fly. It's my understanding that they can, based on other php sources I've seen. $page isn't necessarily a real object - it's more like an array that's retyped using object syntax.

 

Part of the problem with defining $page ahead of time is its dynamic nature. My code is set up to use an html template whose sections are stored in a table. Content for each section is kept in a different table and is loaded into a variable based on the section name. Content is loaded into the section variable in the manner of

 

>$page->{$section->name} = <entry information>;

 

Because the section element of $page is created on the fly I don't see a simple way of declaring it beforehand. The code works well on the test server, but it broke once I uploaded it here.

Posted

I'm not positive, but maybe there is a name conflict between the $_REQUEST 'page' and the $page you create (since I think register globals is on here)? When you try to set $page->name making it an object it wont work since $page is first set as a normal varible as its sent to the script.

 

Try renaming one of them once (for example change it to $mypage->name).

Posted

Yeah, what Frylock said was the first thing to come to mind when i saw your code as a possibility. The only other thing I could think of was to check the scope of your variables, but they're all fine from the looks of things.

 

Good luck. :dance:

Posted

Renaming $page did the trick. So apparently there was indeed a conflict there. That also explains why the other script worked, since I use different _GET values in that one (I also took borfast's advice and changed _REQUEST to _GET - thanks). I also had to rename a couple other variables that had the same problem. But it's working great now.

 

Woohoo! My first content management system!

 

Thanks a lot for all the help you guys. It's greatly appreciated.

 

If you want to see the first pass result, go to www.soulfulhealing.com. After I've tweaked it a bit more I'll post it for critique.

 

Regards,

 

Chris

Posted

Thanks for the compliment Jack. Thanks also for posting the "Ultimate Form Mail". It's saved me a lot of time coding the backend.

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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