Problem with $_GET variables...

Thread Solved

Join Date: Sep 2007
Posts: 45
Reputation: verbob is an unknown quantity at this point 
Solved Threads: 1
verbob verbob is offline Offline
Light Poster

Problem with $_GET variables...

 
0
  #1
30 Days Ago
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:
  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:

  1. images.php?id=27&mode=edit

heres is the first part of "imgup.php"

  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??
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #2
30 Days Ago
  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>");?>


  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. .
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #3
30 Days Ago
Use request for receive data

$_request
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso
 
0
  #4
30 Days Ago
Use either GET or POST. Don't use REQUEST as it has security flaws.
Google is your friend.

Use [code] tags.

If you have found a solution to your problem, please mark the thread as SOLVED.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 45
Reputation: verbob is an unknown quantity at this point 
Solved Threads: 1
verbob verbob is offline Offline
Light Poster
 
0
  #5
30 Days Ago
Thanks for the suggestions, but changing to $_REQUEST didn't make a difference.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 45
Reputation: verbob is an unknown quantity at this point 
Solved Threads: 1
verbob verbob is offline Offline
Light Poster
 
0
  #6
30 Days Ago
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 45
Reputation: verbob is an unknown quantity at this point 
Solved Threads: 1
verbob verbob is offline Offline
Light Poster
 
0
  #7
30 Days Ago
Oh my....

$mode should be $_GET['mode']

can't believe I missed that.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC