Copy link to clipboard
Copied
I'm having an odd problem with an admin page I'm creating to add and delete records from our MySQL db with PHP.
The problem is that in Dreamweaver, I have two forms that each can insert into the db, which works, but after the first submit, the tracking variable I'm using "msg=" keeps getting appended to the URL, so I can end up with "http://mysite.com/admin.php?msg=1&msg=1&msg=1&msg=2", etc.
When you do an insert, shouldn't it just put the current "msg=" in the URL or am I missing the point?
Copy link to clipboard
Copied
It's been a while, but I recall that there is a option in the server behavior to preserve querystring values. See if that option is checked.
Copy link to clipboard
Copied
I'm in Dreamweaver CS5.5 and I can't seem to find that option so I'll Google it.
Copy link to clipboard
Copied
I'm using DW CS5.5, and got a parameter duplicated after submitting an Update Behaviored form.
In this Behavior I defined a GoTo page with one parameter.
That same parameter was in the QueryString before submitting the form.
And once I did so, it appeared twice but with different values: the previous one and the one I sent.
Well, I went to the DW generated code, and found out why did that happen: DW simply adds the previous querystring to the querystring defined in the GoTo page link.
I put some code in it and now it works as it should.
The idea is as follows:
- Make an array if the parameters in my new querystring.
- Remove them from the previous querystring
- Add the "processed" previous querystring to the GoTo Link (just as DW does).
Here is the new "Update Behavior" code: (my addings are in bold)
The form is frmChatSesionesEstado1
You'll have to find yours in your code to identify the code of the Update Behavior.
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "frmChatSesionesEstado1")) {
$updateSQL = sprintf("UPDATE chatsesion SET UsuarioID=%s, chatEstadoID=%s WHERE chatsesionID=%s",
GetSQLValueString($_POST['hidUsuarioID'], "int"),
GetSQLValueString($_POST['hidChatEstadoID'], "int"),
GetSQLValueString($_POST['cmbChatSesionID'], "int"));
mysql_select_db($database_conn1800chat, $conn1800chat);
$Result1 = mysql_query($updateSQL, $conn1800chat) or die(mysql_error());
$updateGoTo = "1800chatOperador.php?chatsesionID=" . $_POST['cmbChatSesionID'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$OldQueryString = $_SERVER['QUERY_STRING']; // New variable to modify contents of Previous QueryString
if (strpos($updateGoTo,"?")>=0) // Ask if there is a "?" in the GoTo link - if so, there is a new QueryString
{
$NewQueryString = substr($updateGoTo, strpos($updateGoTo,"?")+1);
$ParametrosConIgual = explode("&",$NewQueryString); // Create an array of the "Paramname=ParamValue" of the new QueryString
foreach ($ParametrosConIgual as $Parametro) //Loop through that array looking for each parameter in the Old QueryString
{
$Parametro = preg_replace ('/=(.*)/', "", $Parametro); // Remove the "=ParamValue" so that only the "ParamName" is in the variable
if(preg_match('/'.$Parametro.'(.*)&/', $OldQueryString)==1) // Is there any string starting with this "Paramname" and ending in "&" in the old QS?
{
$OldQueryString = preg_replace("/".$Parametro.'(.*)&/', "", $OldQueryString); // If so, delete it from the old QS
}
else if (preg_match("/".$Parametro."(.*)/", $OldQueryString)==1) // Maybe not ending in "&". That would be a parameter at the end of the old QS
{
$OldQueryString = preg_replace("/".$Parametro."(.*)/", "", $OldQueryString); // Delete it as well
}
}
}
if (strlen($OldQueryString)>0) // If there is still anything in the old QS, add it to the GoTo Link.
{
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $OldQueryString;
}
}
header(sprintf("Location: %s", $updateGoTo));
}
You can apply this to Insert and delete behaviours, I guess.
HTH
Ivanov.