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??

Recommended Answers

All 6 Replies

<?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;
.
.
.

Use request for receive data

$_request

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

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

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?

Oh my....

$mode should be $_GET

can't believe I missed that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.