I hate register globals

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nirus
Forum Newbie
Posts: 16
Joined: Fri Dec 17, 2004 12:35 am
Location: Iowa

I hate register globals

Post by nirus »

I am having a realy bad time with register globals. In the following I have $dwnstrmid comming from another page with this:

Code: Select all

<a href="delete_contact.php?dwnstrmid=$myrow&#1111;dwnstrmid]">
I have tried to get it to get dwnstrmid to comply with register globals with "_POST" as shown below but it is not working.

Code: Select all

<?
$dwnstrmid = $_POST&#1111;'dwnstrmid'];
$result = mysql_query("DELETE FROM contact WHERE dwnstrmid=$dwnstrmid ",$connect);
echo "Deleted";
?>
Here is the error that I recieve:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in E:\location\of\my\file\delete_contact.php on line 2

Can some one point me to a good, basic, cut and dry tutorial on php, SQL, and regiter globals or explain here what is wrong with the above...syntax or am I completly off? I researched a little and thought I had it down but I guess not :)

Any help would make me :lol:

-Nirus
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Execute the following after mysql_query() and you'll see the problem:

Code: Select all

<?php
echo mysql_error();
?>
nirus
Forum Newbie
Posts: 16
Joined: Fri Dec 17, 2004 12:35 am
Location: Iowa

Post by nirus »

Found the sql syntax error and corrected it. Now it just comes back and says deleted but the record is not deleted.

Code: Select all

<?
include "header.php";
$dwnstrmid = $_POST&#1111;'dwnstrmid'];
$result = mysql_query("DELETE FROM contact WHERE dwnstrmid='$dwnstrmid' ",$connect);
echo "Deleted";
echo mysql_error();
?>
-nirus
nirus
Forum Newbie
Posts: 16
Joined: Fri Dec 17, 2004 12:35 am
Location: Iowa

Post by nirus »

heeeyyaah. For those of you wondering...the next person to come by...

this is what worked for me:

Code: Select all

<?
include "header.php";
$dwnstrmid = $_GET&#1111;'dwnstrmid'];
$result=mysql_query("DELETE FROM contact WHERE dwnstrmid='$dwnstrmid' ",$connect);
echo "Deleted";
?>
Hope this helps someone
-nirus
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Also for future reference ... if the value could be coming from both a url ($_GET) or a form post ($_POST) then you can use $_REQUEST['var']
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Be careful with using $_REQUEST because it also gets variables from the $_COOKIE array. So if you have a variable set in any of $_POST, $_GET, $_COOKIE that are the same, you can't guarantee that $_REQUEST gives you the value you are looking for.
Post Reply