Copy link to clipboard
Copied
Can anyone see what is wrong with this script?
All I am doing is creating a new entry on an MySQL database then forwarding the visitor to the same page with ?msg=thanks appended to the URL so that I can display a different page saying they have successfully added their name to the database.
For some reason all I get in the URL is ALWAYS exactly the same page and a ? added to the URL. Whatever I place in the $insertGoTo clause I always get it coming back to the same page.
Any ideas?
The full URL of the demo page is: http://www.maisonhomeinteriors.com/JoinOurMailingListTEST.php
Here is the script for the page:
THANKS
-----------
<?php require_once('Connections/maison_connection.php'); ?>
<?php $urladmin = (isset($_GET["admin"])) ? $_GET["admin"] : ""; ?>
<?php $urlupdate = (isset($_GET["update"])) ? $_GET["update"] : ""; ?>
<?php $urlmsg = (isset($_GET["msg"])) ? $_GET["msg"] : ""; ?>
<?php $urlstore = (isset($_GET["store"])) ? $_GET["store"] : ""; ?>
<?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"] == "contactUsForm")) {
$insertSQL = sprintf("INSERT INTO MailingList (Name, Phone, Email, Address1, Address2, Address3, Town, County, PostCode, MailOut) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['phone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['address1'], "text"),
GetSQLValueString($_POST['address2'], "text"),
GetSQLValueString($_POST['address3'], "text"),
GetSQLValueString($_POST['town'], "text"),
GetSQLValueString($_POST['county'], "text"),
GetSQLValueString($_POST['postcode'], "text"),
GetSQLValueString($_POST['Store'], "text"));
mysql_select_db($database_maison_connection, $maison_connection);
$Result1 = mysql_query($insertSQL, $maison_connection) or die(mysql_error());
$insertGoTo = "JoinOurMailingListTEST.php?msg=thanks";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_maison_connection, $maison_connection);
$query_addToMailingList = "SELECT * FROM MailingList";
$addToMailingList = mysql_query($query_addToMailingList, $maison_connection) or die(mysql_error());
$row_addToMailingList = mysql_fetch_assoc($addToMailingList);
$totalRows_addToMailingList = mysql_num_rows($addToMailingList);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Maison - Join Our Mailing List</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf("#")!=0){ d.MM_p
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
if (event == "init" && args.length > 2) {
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
nbArr[nbArr.length] = img;
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = args[i+1];
nbArr[nbArr.length] = img;
} }
} else if (event == "over") {
document.MM_nbOver = nbArr = new Array();
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args)) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
nbArr[nbArr.length] = img;
}
} else if (event == "out" ) {
for (i=0; i < document.MM_nbOver.length; i++) {
img = document.MM_nbOver; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
} else if (event == "down") {
nbArr = document[grpName];
if (nbArr)
for (i=0; i < nbArr.length; i++) { img=nbArr; img.src = img.MM_up; img.MM_dn = 0; }
document[grpName] = nbArr = new Array();
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
nbArr[nbArr.length] = img;
} }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args+".location='"+args[i+1]+"'");
}
//-->
</script>
<link href="cssStyles/maisonCSS.css" rel="stylesheet" type="text/css" />
</head>
<body onload="MM_preloadImages('images/navigationRH/RHnavigation_05OVER.gif','images/navigationRH/RHnavigation_07.gif','images/navigationRH/RHnavigation_09.gif','images/navigationRH/RHnavigation_10.gif','images/navigationRH/RHnavigation_13.gif','images/navigationRH/RHnavigation_05.gif','images/navigationRH/RHnavigation_07OVER.gif','images/navigationRH/RHnavigation_09OVER.gif','images/navigationRH/RHnavigation_10OVER.gif','images/navigationRH/RHnavigation_13OVER.gif')">
<div id="infoText">
<table width="701" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<h1>Join our Mailing List</h1>
<p> </p>
<p>• <span class="redType"><a href="JoinOurMailingList.php?admin=yes">FREE ENTRY</a> INTO OUR MONTHLY EMAIL PRIZE
DRAW OF £25 MAISON VOUCHERS</span></p>
<p>• Receive information about new products and special promotions</p>
<p>• Invitations to launch parties in Richmond and Tunbridge Wells</p>
<p>• Invitation to the opening of the new store in Dorking - opening soon!</p>
<p> </p>
<?php if ($update == "updated") { ?>
<p class="redType">THE DATABASE HAS BEEN UPDATED TO ADD THIS CUSTOMER</p><p> </p>
<?php } ?>
<?php if ( $urlmsg <> "thanks" ) { ?>
<form id="contactUsForm" name="contactUsForm" method="POST" action="<?php echo $editFormAction; ?>">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#efefd4" class="formTextRL">
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td> </td>
<td width="10"> </td>
<td colspan="3"><h1>please complete
the form to join our mailing list</h1>
<p class="catalogHeading"> </p>
<p class="boldItalicsNotes">Maison is committed to the privacy of your personal information.
We will not make your name available to any other companies and
will only contact you occassionally with specific offers or events
that may be of interest to you.</p>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">nearest<br />
Store</td>
<td width="10"> </td>
<td colspan="3" align="left" valign="bottom">
<p class="chooseStore">
<label>
<input type="radio" name="Store" value="2" id="Store_0" />
Tunbridge Wells</label>
<label>
<input type="radio" name="Store" value="3" id="Store_1" />
Richmond</label>
<label>
<input type="radio" name="Store" value="4" id="Store_2" />
Dorking</label>
<label>
<input name="Store" type="radio" id="Store_3" value="1" checked="checked" />
No Local Store</label>
</p>
</td>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">name</td>
<td width="10"> </td>
<td colspan="3"><input name="name" type="text" class="formFields" id="name" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">email</td>
<td width="10"> </td>
<td colspan="3"><input name="email" type="text" class="formFields" id="email" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">phone</td>
<td width="10"> </td>
<td colspan="3"><input name="phone" type="text" class="formFields" id="phone" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">address 1</td>
<td width="10"> </td>
<td colspan="3"><input name="address1" type="text" class="formFields" id="address1" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">address 2</td>
<td width="10"> </td>
<td colspan="3"><input name="address2" type="text" class="formFields" id="address2" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">address 3</td>
<td width="10"> </td>
<td colspan="3"><input name="address3" type="text" class="formFields" id="address3" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">town</td>
<td width="10"> </td>
<td colspan="3"><input name="town" type="text" class="formFields" id="town" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">county</td>
<td width="10"> </td>
<td colspan="3"><input name="county" type="text" class="formFields" id="county" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR">postcode</td>
<td width="10"> </td>
<td colspan="3"><input name="postcode" type="text" class="formFields" id="postcode" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="formHeadingsRR"> </td>
<td> </td>
<td colspan="3">
<?php if ($urladmin == "yes") { ?>
<input name="joinMailingList2" type="submit" id="joinMailingList2" onclick="MM_validateForm('name','','R','postcode','','R');return document.MM_returnValue" value="YES! please add me to the Maison Mailing List" />
<?php } ?>
<?php if ($urladmin <> "yes") { ?>
<input name="joinMailingList2" type="submit" id="joinMailingList2" onclick="MM_validateForm('name','','R','email','','RisEmail','address1','','R','town','','R','postcode','','R');return document.MM_returnValue" value="YES! please add me to the Maison Mailing List" />
<?php } ?>
<a href="ContactUs.php" target="_self" class="commentText"></a></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td class="formSpacerWidth"> </td>
</tr>
<tr>
<td> </td>
<td width="10"> </td>
<td><input name="reset2" type="reset" id="button" onclick="MM_goToURL('parent','http://www.maisonhomeinteriors.com/index.php');return document.MM_returnValue" value="NO, please do NOT add me to the mailing list" /> </td>
<td align="right"><a href="ContactUs.php" target="_self" class="commentText">CONTACT US</a></td>
<td class="formSpacerWidth"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="contactUsForm" />
</form>
<?php } ?>
<?php if ( $urlmsg == "thanks" ) { ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#efefd4" class="formTextRL">
<tr>
<td class="formHeadingsRR"> </td>
<td width="10"> </td>
<td> </td>
</tr>
<tr>
<td class="formHeadingsRR"> </td>
<td width="10"> </td>
<td><h1>Thank you for joining
our mailing list</h1></td>
</tr>
<tr>
<td class="formHeadingsRR"> </td>
<td width="10"> </td>
<td><h3>You have been entered into the latest monthly prize draw.</h3></td>
</tr>
<tr>
<td class="formHeadingsRR"> </td>
<td width="10"> </td>
<td><a href="WeddingList.php" target="_self"></a></td>
</tr>
<tr>
<td class="formHeadingsRR"> </td>
<td width="10"> </td>
<td><a href="ContactUs.php" target="_self" class="commentText">CONTACT US</a></td>
</tr>
<tr>
<td class="formHeadingsRR"> </td>
<td width="10"> </td>
<td align="left"><a href="WeddingList.php" target="_self"></a></td>
</tr>
</table>
<?php } ?>
<p> </p>
<h4><strong>Congratulations to the following who have won the prize draw of £25 in Maison Gift Vouchers…</strong></h4>
<p>Jayne McCarthy, who has won the September 2010 prize draw.</p>
<p>Eileen Leahy, who has won the August 2010 prize draw.</p>
<p>Jane Peirce, who has won the July 2010 prize draw.</p>
<p>Carolyn Morris, who has won the June 2010 prize draw.</p>
<p>Juliet Peters, who has won the May 2010 prize draw.</p>
<p>Mrs H Hunter, who has won the April 2010 prize draw.</p>
<p>Mrs Sarah Simpson, who has won the March 2010 prize draw.</p>
<p>Mrs Katya Wright, who has won the February 2010 prize draw.</p>
<p>Fern Canning, who has won the January 2010 prize draw.</p>
<p>Mrs D Grange, who has won the December 2009 prize draw.</p>
<p>Stephanie Campbell, who has won the November 2009 prize draw.</p>
<p>Claire Langstaff, who has won the October 2009 prize draw.</p>
<p>Mrs Bodenham, who has won the September 2009 prize draw.</p>
<p>Catherine Dench, who has won the August 2009 prize draw.</p>
<p>Jana Severinova, who has won the July 2009 prize draw.</p>
<p> </p></td>
</tr>
</table>
<div id="giftVoucher"><img src="images/joinOurMailingList/DemoVoucher.jpg" width="200" height="100" /></div>
</div>
<div id="mailingListPromoMask"></div>
<? require_once("navigationTopNoHeadings.php"); ?>
<? require_once("navigation.php"); ?>
</html>
<?php
mysql_free_result($addToMailingList);
?>
Copy link to clipboard
Copied
colinwalton wrote:
For some reason all I get in the URL is ALWAYS exactly the same page and a ? added to the URL. Whatever I place in the $insertGoTo clause I always get it coming back to the same page.
The problem is almost certainly caused by the blank line between these blocks of code:
<?php require_once('Connections/maison_connection.php'); ?> <?php $urladmin = (isset($_GET["admin"])) ? $_GET["admin"] : ""; ?>
<?php $urlupdate = (isset($_GET["update"])) ? $_GET["update"] : ""; ?>
<?php $urlmsg = (isset($_GET["msg"])) ? $_GET["msg"] : ""; ?>
<?php $urlstore = (isset($_GET["store"])) ? $_GET["store"] : ""; ?>
<?php
if (!function_exists("GetSQLValueString")) {
There must be NO whitespace or other output before the call to header().
See the following article for a detailed explanation: http://kb2.adobe.com/community/publishing/505/cpsid_50572.html.
Copy link to clipboard
Copied
AAAGGGHHH!!!!
I can't believe it was that simple!
Thank you SO much (again!)
C
Colin Walton
WaltonCreative
Copy link to clipboard
Copied
colinwalton wrote:
AAAGGGHHH!!!!
I can't believe it was that simple!
😉
It sounds as though you have display_errors turned off. Normally, you would see a warning that headers have already been sent. Turning off display_errors on a remote server is good for security, but bad for testing. I always recommend testing locally, but if you want to test on a remote server, it's a good idea to put this at the top of a script:
<?php ini_set('display_errors', '1'); ?>
Remove that line once you have finished testing.
This technique works for all error messages, except syntax errors. If you have a syntax error, and display_errors is turned off, you just get a blank screen.
Copy link to clipboard
Copied
Gosh how clever! thank you!
C
Colin Walton
WaltonCreative