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

After Deleting, GoTo

Participant ,
May 17, 2012 May 17, 2012

I have a selection page showing filtered records from a table.  When I click Delete (column in display table), I go to a confirmation page.  When I click delete, the record is deleted, but instead of then going to the page specified, it displays the delete page again with the same parameters originally sent.  How can I get it to go back to the filtered display?  I have specified both the page AND add the parameter for the filter.  I've done and redone, but can't get back to the page.

TOPICS
Server side applications
2.7K
Translate
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
Community Expert ,
May 19, 2012 May 19, 2012

What language?  Can you post the code you have that's not redirecting properly?

Translate
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
Participant ,
May 21, 2012 May 21, 2012

SORRY!  I send only the body of my code, and you couldn't tell what's going on without the whole file!

Many thanks for any help!

Gail

<!-- filename = DeleteText.php -->

<?php require_once('Connections/sainttim.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

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

  $varpage_rsText = $_GET['varpage'];

  $varpageSend = $_GET['varpage'];

}

if ((isset($_POST['home_key'])) && ($_POST['home_key'] != "")) {

  $deleteSQL = sprintf("DELETE FROM Homepage_text WHERE home_key=%s",

                       GetSQLValueString($_POST['home_key'], "int"));

  mysql_select_db($database_sainttim, $sainttim);

  $Result1 = mysql_query($deleteSQL, $sainttim) or die(mysql_error());

  $deleteGoTo = "TextPageDisplayAll.php?varpage=<?php echo $varpageSend ?>";

  if (isset($_SERVER['QUERY_STRING'])) {

    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";

    $deleteGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $deleteGoTo));

}

$colname_rsText = "-1";

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

  $colname_rsText = $_GET['recid'];

}

mysql_select_db($database_sainttim, $sainttim);

$query_rsText = sprintf("SELECT * FROM Homepage_text WHERE home_key = %s", GetSQLValueString($colname_rsText, "int"));

$rsText = mysql_query($query_rsText, $sainttim) or die(mysql_error());

$row_rsText = mysql_fetch_assoc($rsText);

$totalRows_rsText = mysql_num_rows($rsText);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Delete Text</title>

<link href="css/oneColFixCtrHdr.css" rel="stylesheet" type="text/css" />

<link href="css/main.css" rel="stylesheet" type="text/css" />

</head>

<body class="oneColFixCtrHdr">

<div id="container">

  <!-- include file has header and menu -->

          <?php require_once('AdminIncludeHead.php'); ?>

  <div id="mainContent">

    <h1> </h1>

    <h1>Delete Text from <?php echo $varpageSend?> Page</h1>

  <form id="form1" name="form1" method="post" action="">

    <p> </p>

    <p>

      <input type="hidden" name="home_key" id="num_key" value=<?php echo $row_rsText['home_key']; ?>/>

      <input type="hidden" name="varpageSend" id="hiddenField" value=<?php echo $row_rsText['textpage']; ?>/>

    </p>

    <p span class="LgBlueHdr"><?php echo $row_rsText['p_heading']; ?></span></span>

    </p>

    <p> </p>

    <p span class="LgBlueHdr"><?php echo $row_rsText['p_text']; ?></span></span></p>

    <p> </p>

    <p> </p>

    <table width="500" align="center" border="1" cellspacing="1" cellpadding="1">

      <tr>

        <td class="GreenHdrGray"><a href="TextPageDisplayAll.php?varpage=<?php echo $row_rsText['textpage']; ?>">Cancel & Return to Display</a></td>

        <td><input name="Delete" type="submit" class="RedHdrRv" id="Delete" value="Delete This Entry" /></td>

      </tr>

    </table>

<p> </p>

    <p> </p>

  </form>

  <p> </p>

    <!-- end .content --></div>

  <p><br class="clearfloat" />

<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->

   

  </p>

  <div id="footer">Copyright &copy;2010<br />St. Timothy's Episcopal Church<br />All Rights Reserved

  <!-- end #footer --></div>

  <!-- end .container --></div>

</body>

</html>

<?php

mysql_free_result($rsText);

?>

Translate
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
Participant ,
May 23, 2012 May 23, 2012

If you would have time to look again, I'd appreciate it!  I posted all the php code.

Thanks,

Gail

Translate
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
Community Expert ,
May 23, 2012 May 23, 2012

Sorry for the delay.  These problems are not as simple to solve as the "my page is out of alignment" posts so I want to make sure I'm reading everything right before answering.

The problem in the code is here:

  $deleteGoTo = "TextPageDisplayAll.php?varpage=<?php echo $varpageSend ?>";

  if (isset($_SERVER['QUERY_STRING'])) {

    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";

    $deleteGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $deleteGoTo));

}

First that varpage should not have the <?php echo statement in it because you are already in PHP, so the line should read:

$deleteGoTo = "TextPageDispalyALl.php?varpage=".$varpageSend;

Then if that is the address you want to send the user to, I'm trying to figure out why the "if --> isset" is being used to test for the Query String when it could just proceed to the "header" code as that uses the $deleteGoTo variable.  I don't think that isset rule is really necessary.

Translate
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
Participant ,
May 24, 2012 May 24, 2012

Thanks so much for responding!  I did as you suggested.  The problem remains that instead of going off to TextPageDisplayAll, it goes to "DeleteText.php?varpage=News&recid=123&ReturnPage=News", which is exactly was sent when DeleteText was called originally!  ????????  I don't understand the isset code - it was inserted by Dreamweaver's DeleteRecord server behavior.  I guess I need to bone up on (?JavaScript?) so I can mess with Dreamweaver's code comfortably.

Translate
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
Community Expert ,
May 25, 2012 May 25, 2012

Not javascript, PHP.  The isset code is testing, if the Query_String, anything after the "?" in an adderess has a value, the $deleteGoTo variable then gets the original query string tagged onto the end.  It's an ugly way of adding any variables back to the URL.  In my personal opinion, that whole block could be done away with.

Instead of deleting it, in case you want the old code or any reason, just comment out that block in PHP by putting a /* before the if statement and a */ after it, just before the header.

If this is not producing the results you want I will need you to do the following.  Before the header statement insert the following code:

echo "URL: ".$deleteGoTo; exit;

________________________________________________________

Ok, here's an addition to what I was going to originally say.  Your action is set to nothing right now.  Is that the way it is on the page?  If so, you need to set the action to some page, even if it is the the page it needs to be entered in.

Translate
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
Participant ,
May 25, 2012 May 25, 2012

THANKS! I have been commenting out the code between $deleteGoTo = and header(sprintf. Glad to know that's ok.

I have fiddled with this file so much that I am sick of it! The delete record server behavior had disappeared, so I reselected it and set the parameters. Dreamweaver adds the new code, but does not delete the old code, so it's there twice. When I delete the old code manually, Dreamweaver then drops the delete record behavior. Right now I have the following code, which is neither deleting the record nor going to the TextDisplayAll.php. It continues to display the same URL that it did when the delete page was called.

I used to do software development, but retired 11 years ago. I used BASIC, RPG, Turbo Pascal, Delphi, and Lotus Notes. I'm new to web design and I love Dreamweaver, but when I get stuck on something like this I feel as if I'm fighting my way out of a paper bag!

Thanks for your responses - I really appreciate your help.

Gail

<!-- filename = DeleteText.php --> <?php require_once('Connections/sainttim.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if ((isset($_GET['varkey'])) && ($_GET['varkey'] != "")) { $deleteSQL = sprintf("DELETE FROM Homepage_text WHERE home_key=%s", GetSQLValueString($_GET['varkey'], "int")); mysql_select_db($database_sainttim, $sainttim); $Result1 = mysql_query($deleteSQL, $sainttim) or die(mysql_error()); $deleteGoTo = "TextPageDisplayAll.php?varpage=$varpageSend"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } if (isset($_GET['varpage'])) { $varpage_rsText = $_GET['varpage']; $varpageSend = $_GET['varpage']; } $colname_rsText = "-1"; if (isset($_GET['recid'])) { $colname_rsText = $_GET['recid']; } mysql_select_db($database_sainttim, $sainttim); $query_rsText = sprintf("SELECT * FROM Homepage_text WHERE home_key = %s", GetSQLValueString($colname_rsText, "int")); $rsText = mysql_query($query_rsText, $sainttim) or die(mysql_error()); $row_rsText = mysql_fetch_assoc($rsText); $totalRows_rsText = mysql_num_rows($rsText); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Delete Text</title> <link href="css/oneColFixCtrHdr.css" rel="stylesheet" type="text/css"/> <link href="css/main.css" rel="stylesheet" type="text/css"/> </head> <body class="oneColFixCtrHdr"> <div id="container"> <!-- include file has header and menu --> <?php require_once('AdminIncludeHead.php'); ?> <div id="mainContent">

 

Delete Text from <?php echo $varpageSend?> Page

<form id="form1" name="form1" method="post" action="<?php echo $deleteFormAction; ?>"> <p> </p> <p> <input type="hidden" name="home_key" id="num_key" value=<?php echo $row_rsText['home_key']; ?>/> <input type="hidden" name="varpagedelete" id="hiddenField" value=<?php echo $row_rsText['textpage']; ?>/> </p> <p span class="LgBlueHdr"><?php echo $row_rsText['p_heading']; ?></span></span> </p> <p> </p> <p span class="LgBlueHdr"><?php echo $row_rsText['p_text']; ?></span></span></p> <p> </p> <p> </p> <table width="500" align="center" border="1" cellspacing="1" cellpadding="1"> <tr> <td class="GreenHdrGray">[Cancel &amp; Return to Display | TextPageDisplayAll.php?varpage=<?php echo $row_rsText['textpage']; ?>]</td> <td><input name="Delete" type="submit" class="RedHdrRv" id="Delete" value="Delete This Entry"/></td> </tr> </table> <p> </p> <p> </p> </form> <p> </p> <!-- end .content --></div> <p><br class="clearfloat"/> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --> </p> <div id="footer">Copyright ©2010<br/>St. Timothy's Episcopal Church<br/>All Rights Reserved <!-- end #footer --></div> <!-- end .container --></div> </body> </html>

<?php

mysql_free_result($rsText);

Translate
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
Participant ,
May 25, 2012 May 25, 2012

I changed my code and put DeleteText.php in the form action. It still doesn't delete the record, but at least the URL changed - now it just reads DeleteText.php with no parameters. I'm using "the missing manual" for help in development.

I don't understand why the Server Behavior is so temperamental - the behavior I've selected drops out for no reason that I've been able to determine. Right now it's there, but not operative apparently.

Translate
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
Participant ,
May 25, 2012 May 25, 2012

I deleted my original file and started over. I now can delete the file, and it does go to the right target. However, the variable being sent is blank. I COULD live with that, but my users (church staff) would find it very confusing.

I don't know if I have maxed out available space on the forum, or whether my just-updated Safari is having trouble displaying, but I cannot view the discussion in my browser. I won't send the code in case it's space.

I have a hidden field with name varpageSend that retrieves the variable. I'm using $varpageSend as the variable to send with the deleteGoTo. The form action is DeleteText.php, the same file. Is it deleting the record, which leaves variable unassigned, coming back to DeleteText with my hidden field now undefined, before going off to TextDisplayAll?

At one point I changed the variable on the deleteGoTo, and the delete record dropped out of the Server Behavior display. Now I know - it takes very little for that to happen!

Thanks again,

Gail

Translate
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
Participant ,
May 25, 2012 May 25, 2012

GOT IT! Apparently you can't specify a parameter with the $insertGoTo, $updateGoTo, or $deleteGoTo. I set a variable $NextPage="destination.php?varpage=".destinationvar."; Then set $deleteGoTo=$NextPage. It works!!! Also works with insert. I haven't gotten update working yet, but I'll try again.

Thanks,

Gail

Translate
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
Participant ,
May 29, 2012 May 29, 2012
LATEST

I thought I had the problem solved. I have Insert record, Update record, and Delete record routines for one table that are working just fine. (AFTER I set Form action="<?php echo $deleteFormAction; ?>"). I have put together routines to insert, update, and delete records from another table. Insert & update are fine, and the delete routine works, but stays on the confirmation page with blank fields. I added the echo code as you suggested, and the URL is exactly what it needs to be.

I have printed the code for the delete that is working and the one that is not. Except for field differences, the code is IDENTICAL. One works, one does not. If you don't mind and have a suggestion, I would much appreciate it.

Thanks,

Gail

Translate
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
Participant ,
May 19, 2012 May 19, 2012

GLADLY!  Thanks for the response!

  <div id="mainContent">

    <h1> </h1>

    <h1>Delete Text from <?php echo $varpageSend?> Page</h1>

  <form id="form1" name="form1" method="post" action="">

    <p> </p>

    <p>

      <input type="hidden" name="home_key" id="num_key" value=<?php echo $row_rsText['home_key']; ?>/>

      <input type="hidden" name="varpageSend" id="hiddenField" value=<?php echo $row_rsText['textpage']; ?>/>

    </p>

    <p span class="LgBlueHdr"><?php echo $row_rsText['p_heading']; ?></span></span>

    </p>

    <p> </p>

    <p span class="LgBlueHdr"><?php echo $row_rsText['p_text']; ?></span></span></p>

    <p> </p>

    <p> </p>

    <p> </p>

    <table width="500" align="center" border="1" cellspacing="1" cellpadding="1">

      <tr>

        <td class="GreenHdrGray"><a href="TextPageDisplayAll.php?varpage=<?php echo $row_rsText['textpage']; ?>">Cancel & Return to Display</a></td>

        <td><input name="Delete" type="submit" class="RedHdrRv" id="Delete" value="Delete This Entry" /></td>

      </tr>

    </table>

<p> </p>

    <p> </p>

  </form>

  <p> </p>

    <!-- end .content --></div>

Translate
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