LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 07-12-2010, 09:19 AM   #1
rmknox
Member
 
Registered: May 2010
Posts: 351

Rep: Reputation: 29
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?

###
 
Old 07-12-2010, 09:24 AM   #2
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
$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
}
 
1 members found this post helpful.
Old 07-12-2010, 09:35 AM   #3
rmknox
Member
 
Registered: May 2010
Posts: 351

Original Poster
Rep: Reputation: 29
rcsiw
Thank you so much
Dick

What an incredibley good resource.

Last edited by rmknox; 07-12-2010 at 09:44 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP / Mysql Question mattmc97 Programming 3 02-17-2006 08:46 PM
Very basic newbie question regarding MySQL crispyleif Linux - Software 9 11-07-2005 11:13 PM
PHP/MySQL table question newuser455 Programming 10 11-03-2005 04:50 AM
PHP/MySQL Question Corey Edwards Linux - Software 4 01-14-2005 12:18 PM
php mysql question infected Programming 2 10-31-2004 09:50 PM


All times are GMT -5. The time now is 04:21 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration