p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 (http://p2p.wrox.com/forumdisplay.php?f=476)
-   -   help with passing a variable from a form field via url (http://p2p.wrox.com/showthread.php?t=73201)

Igor Astakhov March 9th, 2009 11:34 PM

help with passing a variable from a form field via url
 
<?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"] == "userform")) {
$insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, province, country, postCode, tel, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['firstName'], "text"),
GetSQLValueString($_POST['Surname'], "text"),
GetSQLValueString($_POST['address1'], "text"),
GetSQLValueString($_POST['address2'], "text"),
GetSQLValueString($_POST['town'], "text"),
GetSQLValueString($_POST['province'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['postcode'], "text"),
GetSQLValueString($_POST['telephone'], "text"),
GetSQLValueString($_POST['email'], "text"));
mysql_select_db($database_connHotel, $connHotel);
$Result1 = mysql_query($insertSQL, $connHotel) or die(mysql_error());
$insertGoTo = "booking_details.php?$email=" . $HTTP_POST_VARS['email'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>


its not grabbing the email from the form and passing it on to the next page via the url

philip_cole March 10th, 2009 08:02 AM

Hi Igor,

Most of the code is using $_POST which is fine, but the line to create the url is using $HTTP_POST_VARS. $HTTP_POST_VARS is deprecated in PHP5 in favour of $_POST, and I believe it is no longer available in version 6.
Just use $_POST['email'] as with the rest of the page and it should work fine.

If for some reason this does not work, check if the email is being added to the database, as that is using the same post value.

HTH
Phil

Igor Astakhov March 10th, 2009 02:00 PM

Dear Phil,

thank you very much for your help indeed it does work. See i got this old book i am working with Dreamweaver MX PHP Webdevelopment and no one replied in that forum so i came here and u helped. I really appriciate it once i am done with this one ill move on to the next newer book.

Sincerely,

Igor


All times are GMT -4. The time now is 09:11 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.