LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Very basic php-mysql question (http://www.linuxquestions.org/questions/linux-server-73/very-basic-php-mysql-question-819404/)

rmknox 07-12-2010 09:19 AM

Very basic php-mysql question
 
MY PROBLEM

Very new to php-mysql

I am having trouble using the querystring. In the browser address field I type

http://localhost/test.php?id=1

In my php script I expect that $id will be defined.
I code

if ($id) { etc

and expect the test to be true if id exists.

Regardless of whether I issue
http://localhost/test.php?id=1
or
http://localhost/test.php

It is not true

I'm sure there is something I havent learned yet - can someone give me a pointer?

DISTRIBTION
Fedora 2.6.31.5-127.fc12.i686
Mysql 5.1.47
Apache 2.2.15

BACKGROUND
Long ago (maybe 15 years) I did a little active web work .

At that time I used the cgi interface and a C program.

As I recall, I parsed an environmental variable to extract information like form results and the query string. My impression is that this is done for me in php-mysql.

Maybe I'm confused?

Maybe I need to use some function to obtain this data?

###

rsciw 07-12-2010 09:24 AM

$id doesn't exist.

if you pass variables through the URL, you get it like this:

$id = $_GET['id'];

if ($id)
{
//etc...
}

Make >>sure<< to sanitize >>any<< input you get through the URL, e.g.

$id = striptags(strip_slashes($_GET['id']));

to remove slashes and html/php tags etc. (google for SQL injection, XSS etc.)

also, you may want to check if the $id is numeric, done through

if (is_numeric($id))
{
//etc.
}
else
{
//errormsg
}

rmknox 07-12-2010 09:35 AM

rcsiw
Thank you so much
Dick

What an incredibley good resource.


All times are GMT -5. The time now is 11:54 AM.