Help with conditionally redirecting to url upon form submission

I need some help modifying the attached code. It works fine but I need to redirect the user to a different URL if the passed value of form field ‘Paid’ = Y

This is auto generated from dreamweaver:

[php]<?php require_once('Connections/DD.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 Orders (Name, Email, Team, Player_Num, YouthSmall, YouthMedium, YouthLarge, YouthXL, AdultSmall, AdultMedium, AdultLarge, AdultXL, AdultXXL, Total, Paid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['name'], "text"), GetSQLValueString($_POST['Email'], "text"), GetSQLValueString($_POST['Team'], "text"), GetSQLValueString($_POST['Player_Num'], "text"), GetSQLValueString($_POST['youthsmall'], "int"), GetSQLValueString($_POST['youthmedium'], "int"), GetSQLValueString($_POST['youthLarge'], "int"), GetSQLValueString($_POST['youthXL'], "int"), GetSQLValueString($_POST['AdultSmall'], "int"), GetSQLValueString($_POST['AdultMedium'], "int"), GetSQLValueString($_POST['AdultLarge'], "int"), GetSQLValueString($_POST['AdultXL'], "int"), GetSQLValueString($_POST['AdultXXL'], "int"), GetSQLValueString($_POST['total'], "int"), GetSQLValueString($_POST['Paid'], "text")); mysql_select_db($database_DD, $DD); $Result1 = mysql_query($insertSQL, $DD) or die(mysql_error()); $insertGoTo = "thankyou.html"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?>[/php]

Thank you!

Something, loosely, like this should work…

[php]
if ($_POST[“Paid”]==“Y”) {
header(“Location: PAID_URL”);
} else {
header((“Location: OTHER_NOT-PAID_URL”);
}
[/php]

Ernie’s solution does exactly what you asked for, but I would be hesitant to go that route. It places high reliance that the user would not change the value just to see what happens.

You are using deprecated code that will not work at all in the current version of Php. You need to use PDO with prepared statements.

Sponsor our Newsletter | Privacy Policy | Terms of Service