Redirect after submit - Dev Shed

Discussion in 'PHP' started by asapcorp, Apr 14, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Ok for some reason my script isn't redirecting to the page I want to after a submition has been made. Basically after the user hits submit in the form, it calls up to that php function, which inserts the values from the form into the database. I just want it to after the values are submitted to redirect to a new page. As of right now, its reloading the same page.
     <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
    }
    
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO Comments (Poster, Body, BlogID, `Date`) VALUES (%s, %s, %s, %s)",
                           GetSQLValueString($_POST['Poster'], "text"),
                           GetSQLValueString($_POST['Body'], "text"),
                           GetSQLValueString($_POST['BlogID'], "text"),
                           GetSQLValueString($_POST['Date'], "int"));
    
      mysql_select_db($database_Stock, $Stock);
      $Result1 = mysql_query($insertSQL, $Stock) or die(mysql_error());
      
      $updateGoTo = "blog.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
        $updateGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $updateGoTo));
    }
    ?> 
    Code (markup):

     
    asapcorp, Apr 14, 2007 IP
  2. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Instead of using this

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

    use this one it may work

    header("Location: ", $updateGoTo);
     
    Subikar, Apr 15, 2007 IP
Thread Status:
Not open for further replies.