0

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

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by verbob
0
<?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;
.
.
.
0

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

0

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?

0

Oh my....

$mode should be $_GET

can't believe I missed that.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.