Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Variables not posting
Old 03-30-2009, 05:18 PM Variables not posting
ihsaan's Avatar
Extreme Talker

Posts: 155
Name: Ihsaan
Location: Botswana
Trades: 0
Why are the variables empty? i have two forms a contact.php and a sent.php Here is the php code of the contact.php

Quote:
<?php require_once('../../Connections/db_sq3.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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"] == "request")) {
$insertSQL = sprintf("INSERT INTO request (category, name, email, phone, fax, city, suburb, request, image) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['category'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['phone'], "text"),
GetSQLValueString($_POST['fax'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['suburb'], "text"),
GetSQLValueString($_POST['request'], "text"),
GetSQLValueString($_POST['image'], "text"));

mysql_select_db($database_db_sq3, $db_sq3);
$Result1 = mysql_query($insertSQL, $db_sq3) or die(mysql_error());

$insertGoTo = "sent.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
and here is the code for the sent.php

Quote:
<?php

$name = $_POST['name']; //senders name
$email = $_POST['email']; //senders e-mail adress
$recipient = "ihs44n@hotmail.com"; //recipient
$subject = " request"; //subject

$phone = $_POST['phone'];
$fax = $_POST['fax'];
$city = $_POST['city'];
$suburb = $_POST['suburb'];
$request = $_POST['request'];

$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields


$mail_body = "From: $name \n Email: $email \n Phone: $phone \n Fax: $fax \n City: $city \n Suburb: $suburb \n Request: $request"; //mail body


ini_set('sendmail_from', 'email@addres.com'); //Suggested by "Some Guy"

mail($recipient, $subject, $mail_body, $header); //mail command
?>
The mail() works but the variables are empty. It just displays:


From:
Email:
Phone:
Fax:
City:
Suburb:
Request:

Any idea what to do? Thanx alot
__________________

Please login or register to view this content. Registration is FREE
ihsaan is offline
Reply With Quote
View Public Profile Visit ihsaan's homepage!
 
 
Register now for full access!
Old 03-30-2009, 06:54 PM Re: Variables not posting
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
$_SERVER['QUERY_STRING'] will only hold the GET parameters of the current page, and on the processing script, you are checking the POST parameters. So in short, you are not passing the vars to the next page, and the processing is reading the wrong vars anyways.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-31-2009, 02:13 AM Re: Variables not posting
ihsaan's Avatar
Extreme Talker

Posts: 155
Name: Ihsaan
Location: Botswana
Trades: 0
how would i change this code to actually send the variables to the next page?
__________________

Please login or register to view this content. Registration is FREE
ihsaan is offline
Reply With Quote
View Public Profile Visit ihsaan's homepage!
 
Old 03-31-2009, 08:25 AM Re: Variables not posting
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
use $_GET (not recommended)

or use a form to post

or use session variables

or use cookies
__________________
I AM THE BEAUTIFUL NIGHTMARE

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
dark_lord is offline
Reply With Quote
View Public Profile Visit dark_lord's homepage!
 
Old 03-31-2009, 06:28 PM Re: Variables not posting
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Replace the last seven lines of the code block in contact.php to the following:

PHP Code:
// It is better to use a full url location for a header redirect
$insertGoTo 'http://www.domain.com/sent.php';
 
$params = array();
foreach (
$_POST AS $key => $value$params[$key] = urlencode($value);
header('Location: ' $insertGoTo '?' implode('&'$params)); 
However, the GET parameters are limited in number of charactures (I think its 256 chars), so it may cutoff some information if its too long.

Then change all the $_POST to $_GET in the sent.php script (or even $_REQUEST will work).

This will solve your immediate problem, but why don't you just go ahead and add the sent.php script using an include, and then redirect the user to a confirmation page. That way the process won't require to rediect the page needing to worry about passing vars.

If you want to apply the vars to the next page, you can also pass the insert_id of the SQL row created and read that info.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Variables not posting
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23369 seconds with 12 queries