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

How do I change the behaviour of an update button.

New Here ,
Feb 27, 2010 Feb 27, 2010

I have a variable - $UpdateFlag, which contains a string and updates a table with it on the click of the update button.

The problem I have is that if the string is blank, I don't want to update, and I want the button to exit instead.

here's the code. At the moment the button does nothing if $UpdateFlag is blank.

How do I change the behaviour of the button so that it can update or exit based on $UpdateFlag?

<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1") and $UpdateFlag !='' ) {
  $updateSQL = sprintf("UPDATE offer SET status=%s WHERE offer_id=%s",
                       GetSQLValueString($UpdateFlag ,"text"),
                       GetSQLValueString($_GET['offer_id'], "int"));

  mysql_select_db($database_guitarswap_db, $guitarswap_db);
  $Result1 = mysql_query($updateSQL, $guitarswap_db) or die(mysql_error());


  $updateGoTo = "Member2.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
    echo OK;
  }
  header(sprintf("Location: %s", $updateGoTo));

}

?

TOPICS
Server side applications
387
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
LEGEND ,
Feb 27, 2010 Feb 27, 2010
LATEST

Add an else statement to do what you want if the flag is empty.

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1") and $UpdateFlag !='' ) {
  $updateSQL = sprintf("UPDATE offer SET status=%s WHERE offer_id=%s",
                       GetSQLValueString($UpdateFlag ,"text"),
                       GetSQLValueString($_GET['offer_id'], "int"));

  mysql_select_db($database_guitarswap_db, $guitarswap_db);
  $Result1 = mysql_query($updateSQL, $guitarswap_db) or die(mysql_error());

$updateGoTo = "Member2.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
    echo OK; // <-- This will cause a parse error
  }
  header(sprintf("Location: %s", $updateGoTo));

} else {

  //do something else

}

Note that your echo statement will cause a parse error. OK is a string, and should be in quotes. Also, it will prevent the redirect from working.

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