954,113 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem with $_GET variables...

I am writing a script to add and edit listings in a realestate site.

For some reason I can't get the variables from the url to recognize properly.

heres the "problem" part of the script:

<?php 
require_once "../dbconnect.php"; // include the database information 
// if the 'mode' is set in the url (i.e. is the originating call is from new (mode is not set from this file) or edit )
if (isset($mode)) { 
	// get the id of the row to be editted from the url
	$editid = $_GET['id'];
	//retrieve the old pictures field and place into temp
	$old =  mysql_query("SELECT * FROM commercial WHERE id = ".$editid);
	$rowold = mysql_fetch_assoc($old);
	$pictures = $rowold['pictures'];
	mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '$pictures' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error()); 
	$result =  mysql_query("SELECT * FROM temp");
	$row = mysql_fetch_assoc($result);
	// get the temp id
	$id = $row['id'];
	$url = "imgup.php?id=".$id."&editid=".$editid;
} else {
		// if temp is not already in use, i.e., pictures not already added, then create temp
		mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error()); 
		$result =  mysql_query("SELECT * FROM temp");
		$row = mysql_fetch_assoc($result);
		$id = $row['id'];
		$url = "imgup.php?id=".$id;
	}
// redirect to upload images script
echo("<script>
<!--
	location.replace(\"".$url."\");
-->
</script>");?>


the url that calls this is:

images.php?id=27&mode=edit


heres is the first part of "imgup.php"

<?php
$id = $_GET['id'];
if  (isset($_GET['editid'])){ 
	$editid = $_GET['editid']; 
	$headerurl = "?id=".$id."&editid=".$editid;
	} 
		else {
			$headerurl = "?id=".$id;
			$editid = "0";
		}
 echo $headerurl;
.
.
.


(If you wonder why I set editid equal to zero, its so that if I need to check later on in this page if editid is set, I just check if its set to 0 instead of using isset...I know its really no big deal, Its just an attempt to keep it easy to read when i look back at it some time later)

headerurl echos as: "id=#" (obvious # represents an actual number, in this case, the number of the "temp id", which I verified to be accurate)

Seems to work fine when I "add a new listing", but when I edit one, thats when the problem appears.

all i can say is -- what the..? What am I missing??

verbob
Junior Poster in Training
62 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 
<?php 
require_once "../dbconnect.php"; // include the database information 
// if the 'mode' is set in the url (i.e. is the originating call is from new (mode is not set from this file) or edit )
if (isset($mode)) { 
	// get the id of the row to be editted from the url
	$editid = $_REQUEST['id'];
	//retrieve the old pictures field and place into temp
	$old =  mysql_query("SELECT * FROM commercial WHERE id = ".$editid);
	$rowold = mysql_fetch_assoc($old);
	$pictures = $rowold['pictures'];
	mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '$pictures' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error()); 
	$result =  mysql_query("SELECT * FROM temp");
	$row = mysql_fetch_assoc($result);
	// get the temp id
	$id = $row['id'];
	$url = "imgup.php?id=".$id."&editid=".$editid;
} else {
		// if temp is not already in use, i.e., pictures not already added, then create temp
		
		mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error()); 
		$result =  mysql_query("SELECT * FROM temp");
		$row = mysql_fetch_assoc($result);
		$id = $row['id'];
		
		$url = "imgup.php?id=".$id;
	}
// redirect to upload images script
echo("<script>
<!--
	location.replace(\"".$url."\");
-->
</script>");?>
<?php
$id = $_REQUEST['id'];
if  (isset($_REQUEST['editid'])){ 
	$editid = $_REQUEST['editid']; 
	$headerurl = "?id=".$id."&editid=".$editid;
	} 
		else {
			$headerurl = "?id=".$id;
			$editid = "0";
		}
 echo $headerurl;
.
.
.
alagirinetaxis
Newbie Poster
15 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 

Use request for receive data

$_request

alagirinetaxis
Newbie Poster
15 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 

Use either GET or POST. Don't use REQUEST as it has security flaws.

kkeith29
Nearly a Posting Virtuoso
1,353 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

Thanks for the suggestions, but changing to $_REQUEST didn't make a difference.

verbob
Junior Poster in Training
62 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 

It appears as though $mode is not recognized as being set. Is there another way to check if a variable is set in the referring url?

verbob
Junior Poster in Training
62 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 

Oh my....

$mode should be $_GET['mode']

can't believe I missed that.

verbob
Junior Poster in Training
62 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You