passing paremeters using the "/" character error

Hi coders,

I’m following a tutorial in the “Restful PHP web services” book and I’m coming across an issue with passing parameters into the URI.

header("Content-Type: text/xml");
$path = $_SERVER['PATH_INFO'];
if($path != null)
{
$path_params = spliti ("/", $path);
}
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
if ($path_params[1] != null)
{
settype($path_params[1], "integer");
$query = "SELECT b.id, b.name, b.author, b.isbn FROM book as b WHERE b.id = $path_params[1]";
} else {
$query = "SELECT b.id, b.name, b.author, b.isbn FROM book as b";
}
$result = mysql_query($query) or die("Query failed: " . mysql_error());

In the above code the goal is to retrieve the info of a book with the ID as the parameter that should be entered into the URI: for example: /library/book.php/2 will look at the ‘2’ as the selected ID
BUT, When I run that link, it says “No input file specified”

I understand the problem, but I don’t know how to fix it.
I believe the problem is that since the URI has “/2” after the filename, it looks for a file with the name “2” but since there is no file, Its not able to load anything.

What i want it to do is to use that as a parameter to retrieve the correct book info. but I don’t know how.

Any help is appreciated.

Thank you

When you see people using links like this they are using mod_rewrite. It essentially allows you to load a URL like /book/2 using a script where the actual URL would be something like book.php?book_id=2 (then in the script you would simply use $_GET[‘book_id’]

Yea i’m trying to figure how to do that myself. Nothing i’ve found is working.

There is a thread here that is exactly what OP want’s to do.

http://www.phphelp.com/forum/index.php?topic=18927.0

My links look like index.php?p=1&act=1 though. All really want it to do to is just be index.php. Might have something with to do with how the menu is being generated though. I’m not going to hijack this thread to solve something that’s a future project now.

What do you mean just index.php?

mod_rewrite could be setup to make domain.com/index.php?p=1&act=1 to be domain.com/1/1

this is typically done just for SEO

I don’t care about where i am in a search engine, its not important to us, i need it more for security. This is the last thing i tried, but it didn’t work

Options +FollowSymlinks -MultiViews RewriteEngine On RewriteBase /testing/new/ RewriteCond %{QUERY_STRING} !^$ RewriteRule index.php$ %{REQUEST_URI}? $1? [L,R] and all the tutorials i found were worse than trying to understand stereo instructions written in a foriegn language.

mod_rewrite is really just about understanding regular expressions. I still don’t understand what you are trying to do. Make a new thread :slight_smile:

Apparently its not possible to use mod rewrite with php files because php is handled first. Oh well, i guess i’m stuck with how it is now.

You should still make a thread, I think we’ve derailed OPs enough, as there may be another solution. Perhaps encoding the query string?

Sponsor our Newsletter | Privacy Policy | Terms of Service