[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:
- <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
- <div data-role="fieldcontain">
- <label for="firstname">First Name</label>
- <input type="text" name="firstname" id="firstname" />
- <label for="lastname">Last Name</label>
- <input type="text" name="lastname" id="lastname" />
- <label for="email">Email</label>
- <input type="text" name="email" id="email" />
- <label for="country">Country</label>
- <select name="country" id="country">
- <option value="Afghanistan">Afghanistan</option>
- <option value=".. ">...</option>
- <option value="Zimbabwe">Zimbabwe</option>
- </select>
-
- <input type="submit" name="send" id="send" value="Submit" />
- </div>
- <input type="hidden" name="MM_insert" value="form1">
- </form>
Here the php (Ttarget URL: $insertGoTo = "index.php" ;):
- <?php require_once('Connections/db_connect.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;
- }
- }
- $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 sharkpledge (firstname, lastname, email, country) VALUES (%s, %s, %s, %s)",
- GetSQLValueString($_POST['firstname'], "text"),
- GetSQLValueString($_POST['lastname'], "text"),
- GetSQLValueString($_POST['email'], "text"),
- GetSQLValueString($_POST['country'], "date"));
- mysql_select_db($database_db_connect, $db_connect);
- $Result1 = mysql_query($insertSQL, $db_connect) or die(mysql_error());
- $insertGoTo = "index.php" ;
- if (isset($_SERVER['QUERY_STRING'])) {
- $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
- $insertGoTo .= $_SERVER['QUERY_STRING'];
- }
- header(sprintf("Location: %s", $insertGoTo));
- }
- ?>