473,511 Members | 15,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parameters in PHP

I have down-loaded several php scripts and am working my way through them
as part of my learning process. I have noticed situations like this:

mysql_query("DELETE FROM $table WHERE id=$id",$db);

where scripts have been called from another script/page with a parameter -
i.e. 'id' is a parameter that is not defined in the script before the
above line is called.

They don't work as they are but I can get the parameters by using
$_GET['id'] or sometimes $_POST['id'].

Is this a result of different versions of php (I am using v5) where
behaviour has changed or is it something else that is going completely
over my head because I am so new to this?

Many thanks.

--
Jeff Gaines Damerham Hampshire UK
It may be that your sole purpose in life is to serve as a warning to others.
Oct 23 '07 #1
9 1558
"Jeff Gaines" <jg************@yahoo.co.ukwrote in
news:xn****************@news.individual.net:

They don't work as they are but I can get the parameters by using
$_GET['id'] or sometimes $_POST['id'].

Is this a result of different versions of php (I am using v5) where
behaviour has changed or is it something else that is going completely
over my head because I am so new to this?

It's a change in the way PHP is set up; In PHP 3 (and possibly early
versions of 4?), "register_globals" was set to "on", which meant that you
didn't have to specify any variables before hand - they were created when
you asked for them.

Most PHP installations now have "register_globals" set to Off, and scripts
like the one you posted will be in trouble unless they're modified like
you've done above. That kind of script is understandable if written before
2002, but really is incredibly bad practice created done afterwards.
http://ca.php.net/register_globals

Oct 23 '07 #2

"Jeff Gaines" <jg************@yahoo.co.ukwrote in message
news:xn****************@news.individual.net...
>I have down-loaded several php scripts and am working my way through them
as part of my learning process. I have noticed situations like this:

mysql_query("DELETE FROM $table WHERE id=$id",$db);

where scripts have been called from another script/page with a parameter -
i.e. 'id' is a parameter that is not defined in the script before the
above line is called.

They don't work as they are but I can get the parameters by using
$_GET['id'] or sometimes $_POST['id'].

Is this a result of different versions of php (I am using v5) where
behaviour has changed or is it something else that is going completely
over my head because I am so new to this?

Many thanks.
Yes, it is because you are so new to this.

The $id is a variable called $id and contains the value you want for the id.
How you get it can be from any of the ways that you set a value for a
variable in php. These include the get, post, or simply setting it to
something or calculating it from something. It is totally independent of
the mysql call (and has to have been set first).

The $db is the variable that contains the connection to the database
obtained from a mysql_connect or a mysql_pconnect call.

These are in php4 and, I assume, from the earliest versions of php (I was
not doing php at that time).

Look at www.w3schools.com for a good tutorial on php (and many other
things). Also, look at www.php.net for just about everything you need in
php.

Good luck and we are here to help you get off the ground.

Shelly
Oct 23 '07 #3

"Good Man" <he***@letsgo.comwrote in message
news:Xn************************@216.196.97.131...
"Jeff Gaines" <jg************@yahoo.co.ukwrote in
news:xn****************@news.individual.net:

>They don't work as they are but I can get the parameters by using
$_GET['id'] or sometimes $_POST['id'].

Is this a result of different versions of php (I am using v5) where
behaviour has changed or is it something else that is going completely
over my head because I am so new to this?


It's a change in the way PHP is set up; In PHP 3 (and possibly early
versions of 4?), "register_globals" was set to "on", which meant that you
didn't have to specify any variables before hand - they were created when
you asked for them.

Most PHP installations now have "register_globals" set to Off, and scripts
like the one you posted will be in trouble unless they're modified like
you've done above. That kind of script is understandable if written
before
2002, but really is incredibly bad practice created done afterwards.
http://ca.php.net/register_globals
Good point! I didn't catch that when I tried to help him. I thought he had
confusion about the mysql call and what the variables were. I misread his
question.

Shelly
Oct 23 '07 #4
In our last episode, <xn****************@news.individual.net>, the lovely
and talented Jeff Gaines broadcast on comp.lang.php:
I have down-loaded several php scripts and am working my way through them
as part of my learning process. I have noticed situations like this:
mysql_query("DELETE FROM $table WHERE id=$id",$db);
where scripts have been called from another script/page with a parameter -
i.e. 'id' is a parameter that is not defined in the script before the
above line is called.
They don't work as they are but I can get the parameters by using
$_GET['id'] or sometimes $_POST['id'].
Is this a result of different versions of php (I am using v5) where
behaviour has changed or is it something else that is going completely
over my head because I am so new to this?
It is not entirely clear by "They don't work" whether your problem is how
the parameters are (should be) passed or with executing a mysql query. So
it is rather to the point how they fail to work. Could you clarify that a
little?

There is no necessary connection between $_POST['id'] (or $_GET['id'])
and $id. If $id doesn't get a value somewhere, perhaps passed as a
parameter, it will have an empty value. This is not really nonsense as
you might well want to delete rows with an empty id field, but if this kind
of clean-up is wanted, it should be done in a more straightforward way with
a instruction as potentially dangerous as DELETE. (And of course, setting
up a table in which a field called 'id' could ever acquire and empty value
would be fairly perverse.

So for this query to be likely, somewhere $id would have to be assigned.

This might be:

$id = <something>;

or

$foo = some_function(<something>);

where some_function is defined:

some_function($id){
....
return $bar;
}

or

some_function(){
$id = func_get_arg(0);
....
return $bar;
}

On the other hand, if "They don't work" has to do with the query failing, I
suppose I should mention that mysql_query() will not work without a database
connection. If it isn't given a connection, it will try to use a previous
connection, and failing that it will try to establish one with mysql_connect
without parameters, a last ditch effort almost certain to fail in real-world
situations.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 454 days to go.
What do you do when you're debranded?
Oct 23 '07 #5
On 23/10/2007 in message
<sl********************@debranded.larseighner.comL ars Eighner wrote:
>In our last episode, <xn****************@news.individual.net>, the lovely
and talented Jeff Gaines broadcast on comp.lang.php:
[snipped]

Many thanks Good Man, Shelly & Lars, I picked Lars' post to reply to as he
has this knack of describing me so well :-)

I think Good Man has probably hit it on the head, this is old code I am
looking at which probably will have worked with earlier versions of php. I
will continue using $_GET['id'] and $_POST['id'] as this seems to be how
to do it now.

Hopefully as I learn I will be able to ask my questions more clearly, at
the moment I am struggling a bit to understand exactly what it is I need
to ask :-)

Thanks again!

--
Jeff Gaines Damerham Hampshire UK
Tell me what you need, and I'll tell you how to get along without it.
Oct 23 '07 #6
"Jeff Gaines" <jg************@yahoo.co.ukwrote in
news:xn****************@news.individual.net:
I think Good Man has probably hit it on the head, this is old code I
am looking at which probably will have worked with earlier versions of
php. I will continue using $_GET['id'] and $_POST['id'] as this seems
to be how to do it now.
Just as an FYI, presuming your code doesn't have any security holes related
to register_globals (ie: if($authorized) { revealSecrets(); } ) then you
can turn the register_globals directive "ON" in php.ini and have that nasty
ol' site work correctly.... admin beware :)

Oct 23 '07 #7
..oO(Jeff Gaines)
>I think Good Man has probably hit it on the head, this is old code I am
looking at which probably will have worked with earlier versions of php. I
will continue using $_GET['id'] and $_POST['id'] as this seems to be how
to do it now.
An addition: If a user-submitted value is used directly in a query
without any validation as it seems to be in this case, then it's very
easy for an attacker to empty the entire table. Read about SQL injection
and how to prevent it.

Micha
Oct 23 '07 #8
Greetings, Jeff Gaines.
In reply to Your message dated Tuesday, October 23, 2007, 19:51:16,

JGI have down-loaded several php scripts and am working my way through them
JGas part of my learning process. I have noticed situations like this:

JGmysql_query("DELETE FROM $table WHERE id=$id",$db);

JGwhere scripts have been called from another script/page with a parameter -
JGi.e. 'id' is a parameter that is not defined in the script before the
JGabove line is called.

JGThey don't work as they are but I can get the parameters by using
JG$_GET['id'] or sometimes $_POST['id'].

It is bad, very bad idea to trust somethig entered by user.
Example?
You have code

"SELECT user_id FROM users WHERE user_name = '{$_POST['name']}' AND user_password = MD5('{$_POST['password']})"

Then I submit the form

name="admin' --"
password="any"

Et voila.. I'm authorized as admin of Your website.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Oct 24 '07 #9
On 24/10/2007 in message <11***********************@freemail.ruAnrDaemon
wrote:
>It is bad, very bad idea to trust somethig entered by user.
I take your point - I am doing this as a hobby at home on my own network
so I have only to protect me from myself :-)

--
Jeff Gaines Damerham Hampshire UK
This is as bad as it can get, but don't bet on it
Oct 24 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
21589
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
2
3882
by: Mark | last post by:
I created a test to check the execution time difference between executing a SQL Server stored procedured using explicit parameters versus not. In one case I created new SqlParameters in the code,...
4
1625
by: Tim::.. | last post by:
Can someone tell me a better way or give me a link that shows a better way to create large numbers of SQL parameters... Example... A better way to write this code! <code> Sub...
14
3245
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
18
4314
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
2
2610
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
12
2649
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
1
2495
by: John Kotuby | last post by:
Hi all, I am working on porting an application from VB6 to VB.NET 2003 and am running into some problems. When declaring and populating the parameters for a SQL Stored Procedure by using the...
0
2072
by: Xah Lee | last post by:
In this article, i explain how the use of bit masks is a hack in many imperative languages. Often, a function will need to take many True/False parameters. For example, suppose i have a function...
2
1719
by: Jared Grant | last post by:
I am trying to find the value from some output parameters from a stored procedure. I have tried several different methods but somehow cannot get it to work. here is my source code: dim dr as...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.