[SOLVED] My form is redirecting to an unexpected place

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

[SOLVED] My form is redirecting to an unexpected place

Post by impulse() »

I have a very small reminder program which gives the option to snooze a reminder. This is done by submitting the value of a drop down menu to $_GET and adding that value onto the unix timestamp currently in the DB.

I should be embarrased for asking this, but why isn't the form redirecting me to snooze2.php?reminderID=X when I submit? It seems to skip redirecting me to that GET value but it inserts the other GET value.

Here is my code:

Code: Select all

<form method = 'GET' action = 'snooze2.php?reminderID=<?php echo $_GET["reminderID"]; ?>'>
  <select name = 'snoozeTime'>
    <option value = '1'> 1 Minutes </option>
    <option value = '5'> 5 Minutes </option>
    <option value = '10'> 10 Minutes </option>
    <option value = '15'> 15 Minutes </option>
    <option value = '20'> 20 Minutes </option>
    <option value = '30'> 30 Minutes </option>
    <option value = '45'> 45 Minutes </option>
    <option value = '60'> 1 Hour </option>
    <option value = '120'> 2 Hours </option>
    <option value = '240'> 4 Hours </option>
    <option value = '1440'> 24 Hours </option>
    <option value = '2880'> 48 Hours </option>
    <option value = '10080'> 1 Week </option>
  </select>
  <input type = 'submit' value = 'Snooze'>
</form>

<?php

$snoozeTime = $_GET["snoozeTime"];
$reminderID = $_GET["reminderID"];

if (!empty($snoozeTime) && ctype_digit($snoozeTime)) {

  $query = mysql_query("SELECT id, remindOn
                        FROM remindersWebCal
                        WHERE id = '$reminderID'");

  while ($res = mysql_fetch_array($query)) {

    $remindTimeFromDB = $res['remindOn'];

  }

  $newRemindTime = $remindTimeFromDB + $snoozeTime * 60;

  mysql_query("UPDATE remindersWebCal
               SET remindOn = '$newRemindTime'
               WHERE id = '$reminderID'");

}
When a user visits snooze2.php they will already have $_GET['reminderID'] set. So, upon visiting the page the url is
snooze2.php?reminderID=x and then once the form is submitted the URL unexpectedly becomes snooze2.php?snoozeTime=x when I was hoping it to be snooze2.php?reminderID=x&snoozeTime=x.

If I place the expected URL in manually the code works.

Regards,
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Not to worry. This was solved by combining POST & GET.

Regards,
Post Reply