Jump to content

[SOLVED] Problem with a "Stay Updated" script


DBookatay

Recommended Posts

I am trying to make a form on my site (http://www.carcityofdanbury.com/inventory.php?status=Error#StayUpdated) where a user enters their email address if they wish to recieve emails when my site is updated, but I'm obviously doing something incorrect, cause the script keeps failing. Can someone show/ tell me what is wrong?

 

The HTML

									<table>
										<tr class="title225"><td height="23" style="padding-left:10px"><a id="StayUpdated"></a><span class="subTitle">Stay Updated</span></td></tr>
										<tr><td class="ContHldr">
											<form action="inventory.php" name="form" method="post" class="no">
											<div align="center">
												<table>
													<tr><td class="frmPad">Want to say updated with all<br />the changes made on our site?</td></tr>
													<tr><td style="padding-top:10px"><? echo $update_errors ?><input name="updated" type="text" class="input" size="30" onclick="if(this.value=='Enter Email Address'){this.value=''}" value="Enter Email Address" /></td></tr>
													<tr><td align="center" style="padding-top:10px"><input type="image" src="images/Default/BTNs/signupOff.gif" srcover="images/Default/BTNs/signupOn.gif" name="submit" /></td></tr>
												</table>
											</div>
											</form>
										<tr><td><img src="images/Default/Titles/btm225.gif" /></td></tr>
									</table>

 

The PHP:

	if(!(empty($_POST['updated']))) { 
	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated']))
	{
		$email = $_POST['updated']; 
	}
	else {
		$email = 'Enter Email Address'; 
	}
}


if ($email == "Enter Email Address") {
	echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>';
} else {
	$querySubmit;
}

$querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">";

 

(I know that the code is much longer and hacked togather than it needs to be, but I am a self admitted "NOOB!")

 

 

oh my mistake then, i didnt know it was a button.

 

use

 

if(isset($_POST['updated'])){
	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated']))
	{
		$email = $_POST['updated']; 
	}
	else {
		$email = 'Enter Email Address'; 
	}



if ($email == "Enter Email Address") {
	echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>';
} else {
	$querySubmit;
}

$querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">";

}

 

Ok, now the script is working, however it is still not 100%.

Even if the user does not enter an email address, and the default "Enter Email Address" is in the field, it still inserts "Enter Email Address" into the dB, instead of blocking it with errors...

      try

 

f(isset($_POST['updated'])){
	if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated']))
	{
		echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>';

	}
	else{		
	$email = $_POST['updated'];			
	$querySubmit;	
	$querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">";

}

}

       try

 

f(isset($_POST['updated'])){
	if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated']))
	{
		echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>';

	}
	else{		
	$email = $_POST['updated'];			
	$querySubmit;	
	$querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">";

}

}

 

Thats it, thanks...

Looking at the script you created, leaves me with a question I always wondered.

I used to use the redirect php script

echo "<meta http-equiv="Refresh" content="0; url=inventory.php?status=Good">

 

but it seams like the java version

<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>

works much quicker.

 

Anyone care to comment?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.