|
|
|
|
![]() ![]() |
Jan 29 2006, 06:08 PM
Post
#1
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 14-February 05 From: Oslo, Norway Member No.: 3,759 |
Well, I am making a full CMS system for my site, and want to make the index.php file to include the view.php?id=1 file. I tried with this code, but it didn't work:
CODE <?php include 'view.php?id=1' ?> This is the error I get: CODE Warning: main(view.php?id=1) [function.main]: failed to open stream: Invalid argument in C:\server\xampp\htdocs\test\index.php on line 1 Warning: main() [function.include]: Failed opening 'view.php?id=1' for inclusion (include_path='.;C:\server\xampp\php\pear\') in C:\server\xampp\htdocs\test\index.php on line 1 So what can I do? |
|
|
|
Jan 29 2006, 06:57 PM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,880 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
Start by using the function in the correct form.
The brackets are required for Include functions to define the target of the file to 'Include'. CODE <?php include('header.html') ?> |
|
|
|
Jan 29 2006, 07:13 PM
Post
#3
|
|
|
Incest is a game the whole family can play. ![]() Group: [MODERATOR] Posts: 1,205 Joined: 11-February 05 From: Heaven Member No.: 3,709 |
Actually, include "bla.php"; is a perfectly good way of including a file.
Here's how to fix the problem:
And that's it ========================================== The reason why it doesn't work is because php looks for the file view.php?id=1 on the filesystem not view.php. |
|
|
|
Jan 29 2006, 08:24 PM
Post
#4
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 14-February 05 From: Oslo, Norway Member No.: 3,759 |
cmatcmextra, I don't have if ($_REQUEST["id"] == "1") in view.php. This is what I have:
CODE $id = $_REQUEST['id'];
|
|
|
|
Jan 29 2006, 09:05 PM
Post
#5
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,880 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
QUOTE(jlhaslip @ Jan 29 2006, 11:57 AM) Well, I'll be darned... it does so work. Thanks for the lesson. Syntax can be so picky about these things sometimes, it was something that I thought might help. |
|
|
|
Jan 29 2006, 10:22 PM
Post
#6
|
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,161 Joined: 9-May 05 From: Brisbane, QLD Member No.: 6,818 |
QUOTE(Amezis @ Jan 30 2006, 04:08 AM) This is the error I get:[code]Warning: main(view.php?id=1) [function.main]: failed to open stream: Invalid argument in C:\server\xampp\htdocs\test\index.php on line 1 What's on line 1 of index.php? |
|
|
|
Jan 30 2006, 08:18 AM
Post
#7
|
|
|
Incest is a game the whole family can play. ![]() Group: [MODERATOR] Posts: 1,205 Joined: 11-February 05 From: Heaven Member No.: 3,709 |
Okay then, in view.php change:
CODE $id = $_REQUEST['id']; To: CODE $id = $view_var; And also, I forgot to add in the last post. Change this in index.php: CODE include 'view.php?id=1' To: CODE include 'view.php'; And making the changes shown in my last post in this topic, your problem should be fixed. edit: fixed typos This post has been edited by cmatcmextra: Jan 30 2006, 08:24 AM |
|
|
|
Jan 30 2006, 01:25 PM
Post
#8
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 14-February 05 From: Oslo, Norway Member No.: 3,759 |
Thanks! It works now
|
|
|
|
Jan 30 2006, 03:36 PM
Post
#9
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 874 Joined: 30-July 04 Member No.: 246 |
Just to avoid future problems, I would recommend changing:
CODE $id = $_REQUEST['id']; To somethingl ike: CODE $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : isset($view_var) ? $view_var : 0; .Changing to just '$id = $view_var;' means it won't work if someone actually accesses view.php directly. Whether or not that's going to happen in your particular circumstance I don't know, but I like to try to avoid potential problems wherever possible. |