944,093 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1022
  • PHP RSS
Oct 27th, 2009
0

Problem with $_GET variables...

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2. require_once "../dbconnect.php"; // include the database information
  3. // 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 )
  4. if (isset($mode)) {
  5. // get the id of the row to be editted from the url
  6. $editid = $_GET['id'];
  7. //retrieve the old pictures field and place into temp
  8. $old = mysql_query("SELECT * FROM commercial WHERE id = ".$editid);
  9. $rowold = mysql_fetch_assoc($old);
  10. $pictures = $rowold['pictures'];
  11. mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '$pictures' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error());
  12. $result = mysql_query("SELECT * FROM temp");
  13. $row = mysql_fetch_assoc($result);
  14. // get the temp id
  15. $id = $row['id'];
  16. $url = "imgup.php?id=".$id."&editid=".$editid;
  17. } else {
  18. // if temp is not already in use, i.e., pictures not already added, then create temp
  19. mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error());
  20. $result = mysql_query("SELECT * FROM temp");
  21. $row = mysql_fetch_assoc($result);
  22. $id = $row['id'];
  23. $url = "imgup.php?id=".$id;
  24. }
  25. // redirect to upload images script
  26. echo("<script>
  27. <!--
  28. location.replace(\"".$url."\");
  29. -->
  30. </script>");?>

the url that calls this is:

PHP Syntax (Toggle Plain Text)
  1. images.php?id=27&mode=edit

heres is the first part of "imgup.php"

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $id = $_GET['id'];
  3. if (isset($_GET['editid'])){
  4. $editid = $_GET['editid'];
  5. $headerurl = "?id=".$id."&editid=".$editid;
  6. }
  7. else {
  8. $headerurl = "?id=".$id;
  9. $editid = "0";
  10. }
  11. echo $headerurl;
  12. .
  13. .
  14. .

(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??
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
verbob is offline Offline
62 posts
since Sep 2007
Oct 27th, 2009
0
Re: Problem with $_GET variables...
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. require_once "../dbconnect.php"; // include the database information
  3. // 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 )
  4. if (isset($mode)) {
  5. // get the id of the row to be editted from the url
  6. $editid = $_REQUEST['id'];
  7. //retrieve the old pictures field and place into temp
  8. $old = mysql_query("SELECT * FROM commercial WHERE id = ".$editid);
  9. $rowold = mysql_fetch_assoc($old);
  10. $pictures = $rowold['pictures'];
  11. mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '$pictures' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error());
  12. $result = mysql_query("SELECT * FROM temp");
  13. $row = mysql_fetch_assoc($result);
  14. // get the temp id
  15. $id = $row['id'];
  16. $url = "imgup.php?id=".$id."&editid=".$editid;
  17. } else {
  18. // if temp is not already in use, i.e., pictures not already added, then create temp
  19.  
  20. mysql_query("INSERT INTO temp (id, pictures) VALUES (NULL, '' )") or die("somthing went wrong during the registration. MySQL said: ".mysql_error());
  21. $result = mysql_query("SELECT * FROM temp");
  22. $row = mysql_fetch_assoc($result);
  23. $id = $row['id'];
  24.  
  25. $url = "imgup.php?id=".$id;
  26. }
  27. // redirect to upload images script
  28. echo("<script>
  29. <!--
  30. location.replace(\"".$url."\");
  31. -->
  32. </script>");?>


PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $id = $_REQUEST['id'];
  3. if (isset($_REQUEST['editid'])){
  4. $editid = $_REQUEST['editid'];
  5. $headerurl = "?id=".$id."&editid=".$editid;
  6. }
  7. else {
  8. $headerurl = "?id=".$id;
  9. $editid = "0";
  10. }
  11. echo $headerurl;
  12. .
  13. .
  14. .
Reputation Points: 10
Solved Threads: 3
Newbie Poster
alagirinetaxis is offline Offline
15 posts
since Oct 2009
Oct 27th, 2009
0
Re: Problem with $_GET variables...
Use request for receive data

$_request
Reputation Points: 10
Solved Threads: 3
Newbie Poster
alagirinetaxis is offline Offline
15 posts
since Oct 2009
Oct 27th, 2009
0
Re: Problem with $_GET variables...
Use either GET or POST. Don't use REQUEST as it has security flaws.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Oct 27th, 2009
0
Re: Problem with $_GET variables...
Thanks for the suggestions, but changing to $_REQUEST didn't make a difference.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
verbob is offline Offline
62 posts
since Sep 2007
Oct 27th, 2009
0
Re: Problem with $_GET variables...
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?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
verbob is offline Offline
62 posts
since Sep 2007
Oct 27th, 2009
0
Re: Problem with $_GET variables...
Oh my....

$mode should be $_GET['mode']

can't believe I missed that.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
verbob is offline Offline
62 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to pass variable between pages, without form???
Next Thread in PHP Forum Timeline: Reister form won't work





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC