Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Alternative page for "After deleting, go to:"

New Here ,
Jun 11, 2009 Jun 11, 2009

Copy link to clipboard

Copied

Hi!

Got a PHP dynamic list page that lists records from two tables in MySql database, the tables got a column named "gk" that makes them different from each other. In one table gk is allways "ÖGK" and in the other table gk is allways "PGA".

Now, in the list page there are a number of buttons that links to insert, update and delete pages. These pages are duplicated for each of the two tables, for example there are one delete record page for a record in the table with ÖGK in the gk column (delete_user.php) and another delete record page for a record in the table with PGA in the gk column (delete_user_pga.php). Actually there are two lis pages to, one list_users.php mentioned obove, this is the master list page with the problem. And one list_users_pga.php that lists only records from PGA table, no problem here.

I got this working so far that I get to the right delete record page (the one that deletes from the corect table ÖGK or PGA), and the record wil be deleted whith this home grown code:

input name="Button2" type="button" class="miniknapp" onclick="MM_goToURL('parent','<?php if ($row_listUsers['gk']== "ÖGK") { echo "delete_user.php"; } elseif ($row_listUsers['gk']== "PGA") { echo "delete_user_pga.php"; } else { echo ""; } ?>?id=<?php echo $row_listUsers['id']; ?>');return document.MM_returnValue" value="Delete"

There are no problems if I from the master list page go to a page that delete or update a record from the ÖGK table couse it folows the "After delete, go to" link that is specified in the delete record dialoge. No problems if I go to a delete or update page from the "List only PGA records" for the same reason.

But if I'm deleting a record from the PGA table it will delete the record properly but redirect to the PGA list page. like it's supposed to do if you got to the page from list_users_pga.php. BUT if you got there from the master list page list_users.php I want to be redirected back to that page where I came from. The same problem occures if I cancel the deletion (cancel script from David Powers book "The Essential Guide to Dreamweaver CS4.... Hello David)

Well, tried with a lot of home cocked code pudding without success:

<?php

if ($row_getUsers['gk']== "ÖGK") { // Show if gk = ÖGK


?>
<?php

if (array_key_exists('cancel', $_POST)) {
header('Location:
http://teeview.se/analys_kund/list_users.php');
exit;
}
if ((isset($_POST['id'])) && ($_POST['id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM analys_kund_pga WHERE id=%s",
                      GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_connect, $connect);
  $Result1 = mysql_query($deleteSQL, $connect) or die(mysql_error());

  $deleteGoTo = "list_users.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}
?>
<?php } // end Show if gk = ÖGK?>


<?php

if ($row_getUsers['gk']== "PGA") { // Show if gk = PGA


?>
<?php

if (array_key_exists('cancel', $_POST)) {
header('Location:
http://teeview.se/analys_kund/list_users_pga.php');
exit;
}
if ((isset($_POST['id'])) && ($_POST['id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM analys_kund_pga WHERE id=%s",
                      GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_connect, $connect);
  $Result1 = mysql_query($deleteSQL, $connect) or die(mysql_error());

  $deleteGoTo = "list_users_pga.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}
?>
<?php } // end Show if gk = PGA?>

The same scenario will of course happens i register and uppdate pages but the solution will also be the same I guess

TOPICS
Server side applications

Views

1.4K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 13, 2009 Jun 13, 2009

Too many question marks maybe??

Yes, you can have only one question mark in a URL. It creates what's called the query string, which should contain all the variables. Separate the variables with an ampersand:

delete_user_pga.php?id=21&returnPage=list_users

Votes

Translate
LEGEND ,
Jun 11, 2009 Jun 11, 2009

Copy link to clipboard

Copied

Thread moved to the appropriate forum: Dreamweaver Application Development.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2009 Jun 11, 2009

Copy link to clipboard

Copied

Ok!

If I skip the cancel script:

if (array_key_exists('cancel', $_POST)) {
header('Location:
http://teeview.se/analys_kund/list_users_pga.php');
exit;
}

And replace it with a javascript goback funktion:

<?Php echo "<form><input type=\"button\" class=\"miniknapp\" value=\"CANCEL\" onClick=\"javascript:history.go(-1)\"></form>";?>

I will return to corect (previous) list page (list_users.php or list_users_pga.php). But if I submit and delet the record i will return to the "afterdeleting, go to" page that might not be the one I came from.

Any one, any idea

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 12, 2009 Jun 12, 2009

Copy link to clipboard

Copied

I'm afraid I'm finding it difficult to follow all your logic, but setting which page the user returns to should be quite simple with conditional logic.

Just add a query string to the end of the URL that sends the user to the correct delete page. For example:

delete.php?returnPage=pga

Then you can check for the value of $_GET['returnPage'] to determine which page to send the user back to. Replace the following line:

$deleteGoTo = "list_users.php";

With this:

if (isset($_GET['returnPage'])) {

  $deleteGoTo = $_GET['returnPage'] . '.php';

} else {

  $deleteGoTo = "list_users.php";

}

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2009 Jun 12, 2009

Copy link to clipboard

Copied

Hello David!

Thanks for your effort, great help. First of all I'm not surprised my "Logic" isn't easy to follow, what a mess

I could not quite get your code to work but I undersood the meening of it so what I did was:

I have already at login pages (one for ÖGK and one for PGA) made session variables so I would know where I came from. they are either $_SESSION['golfklubb'] == 'ÖGK' or $_SESSION['golfklubb'] == 'PGA', I use this for alternative menus to get back to the right list_page for example (if I don't update or delete).

So with your help I modded the deleteGoTo into:

//$deleteGoTo = "list_users_pga.php";


  if ($_SESSION['golfklubb'] == 'ÖGK') {
  $deleteGoTo = "list_users.php"; } else {
  $deleteGoTo = "list_users_pga.php";
}

At this late hour I think I got it to work and that I should be able to use it the same way in register and update pages thanks to you.

Am I being a bad boy, is it stupid in anyway

Ithink this is where I went wrong with the query string:

The original:

<input name="Button2" type="button" class="miniknapp" onclick="MM_goToURL('parent','<?php if ($row_listUsers['gk']== "ÖGK") { echo "delete_user.php"; } elseif ($row_listUsers['gk']== "PGA") { echo "delete_user_pga.php"; } else { echo ""; } ?>?id=<?php echo $row_listUsers['id']; ?>');return document.MM_returnValue" value="RADERA" />

First try with query string:

<input name="Button2" type="button" class="miniknapp" onclick="MM_goToURL('parent','<?php if ($row_listUsers['gk']== "ÖGK") { echo "delete_user.php?returnPage=list_users"; } elseif ($row_listUsers['gk']== "PGA") { echo "delete_user_pga.php?returnPage=list_users"; } else { echo ""; } ?>?id=<?php echo $row_listUsers['id']; ?>');return document.MM_returnValue" value="RADERA" />

This one made a link like "delete_user_pga.php?returnPage=list_users?id=21" The id is getting lost and no record to delete shows up.

Second try:

This one made a link like "delete_user_pga.php?id=21?returnPage=list_users" Record shows up and deletes but return page dont work if list_users.php. Too many question marks maybe??

With the conditional logic:

//$deleteGoTo = "list_users_pga.php";
  if (isset($_GET['returnPage'])) {
  $deleteGoTo = $_GET['returnPage'] . '.php'; } else {
  $deleteGoTo = "list_users_pga.php";
}

I can live with the session variable method, I think but "Got to know"

<input name="Button2" type="button" class="miniknapp" onclick="MM_goToURL('parent','<?php if ($row_listUsers['gk']== "ÖGK") { echo "delete_user.php"; } elseif ($row_listUsers['gk']== "PGA") { echo "delete_user_pga.php"; } else { echo ""; } ?>?id=<?php echo $row_listUsers['id']; ?>?returnPage=list_users');return document.MM_returnValue" value="RADERA" />

Message was edited by: Willymannen

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2009 Jun 13, 2009

Copy link to clipboard

Copied

Too many question marks maybe??

Yes, you can have only one question mark in a URL. It creates what's called the query string, which should contain all the variables. Separate the variables with an ampersand:

delete_user_pga.php?id=21&returnPage=list_users

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2009 Jun 13, 2009

Copy link to clipboard

Copied

LATEST

David Powers tell you what, YOU'RE THE MAN

Works just beautiful, so I keep the querystring method and throw the session garbage in the recykle bin. How great it is to learn new things even at the age of 58 and even if the short summer in Stockholm is raining away outside my window.

Thanks a lot

Willy

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines