[solved] jQM PHP form MySQL plus redirection after submission

[solved] jQM PHP form MySQL plus redirection after submission

I have a PHP form which makes a mysql record. The process itself works perfectly but not the redirection after sending.


Can anybody help me with this. Has this something to do with AJAX? Do I need to switch off Ajax for the form page? that would not be nice.

Cheers
Ralph

Here the form:
  1. <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
  2.   <div data-role="fieldcontain">
  3.     <label for="firstname">First Name</label>
  4.     <input type="text" name="firstname" id="firstname" />
  5.     <label for="lastname">Last Name</label>
  6.     <input type="text" name="lastname" id="lastname" />
  7.     <label for="email">Email</label>
  8.     <input type="text" name="email" id="email" />
  9.     <label for="country">Country</label>
  10.     <select name="country" id="country">
  11.       <option value="Afghanistan">Afghanistan</option>
  12.       <option value=".. ">...</option>
  13.             <option value="Zimbabwe">Zimbabwe</option>
  14.     </select>
  15.     
  16.     <input type="submit" name="send" id="send" value="Submit" />
  17.   </div>
  18.   <input type="hidden" name="MM_insert" value="form1">
  19.   </form>
Here the php (Ttarget URL:  $insertGoTo = "index.php" ;):
  1. <?php require_once('Connections/db_connect.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }

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

  10.   switch ($theType) {
  11.     case "text":
  12.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13.       break;    
  14.     case "long":
  15.     case "int":
  16.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17.       break;
  18.     case "double":
  19.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  20.       break;
  21.     case "date":
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.       break;
  24.     case "defined":
  25.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26.       break;
  27.   }
  28.   return $theValue;
  29. }
  30. }

  31. $editFormAction = $_SERVER['PHP_SELF'];
  32. if (isset($_SERVER['QUERY_STRING'])) {
  33.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  34. }

  35. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  36.   $insertSQL = sprintf("INSERT INTO sharkpledge (firstname, lastname, email, country) VALUES (%s, %s, %s, %s)",
  37.                        GetSQLValueString($_POST['firstname'], "text"),
  38.                        GetSQLValueString($_POST['lastname'], "text"),
  39.                        GetSQLValueString($_POST['email'], "text"),
  40.                        GetSQLValueString($_POST['country'], "date"));

  41.   mysql_select_db($database_db_connect, $db_connect);
  42.   $Result1 = mysql_query($insertSQL, $db_connect) or die(mysql_error());

  43.   $insertGoTo = "index.php" ;
  44.   if (isset($_SERVER['QUERY_STRING'])) {
  45.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  46.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  47.   }
  48.   header(sprintf("Location: %s", $insertGoTo));
  49. }
  50. ?>