...

View Full Version : Message not returning



Sk8er9547
03-15-2004, 08:18 PM
I have a script that is executed when a user hits the submit button. For some reason, when the inputs are correct the page is not returning a thank you page but it is coming up with a blank page. When the inputs are left blank, it returns the correct page. Here is the code:

if($n && $e)
{
$query = "SELECT id FROM newsletter WHERE email='$e'";
$result = @mysql_query($query);
if(mysql_num_rows($result) == 0)
{
$query = "INSERT INTO newsletter (id, name, email)
VALUES('$id', '$n', '$e')";
$result = @mysql_query($query);
if($result)
{
echo "Thanks";

exit();
}
else
{
$message = "You could not be registered at this time. Please try again later.";
}
}
else
{
$message = "The E-Mail $email has already been entered into our database.";
}
mysql_close();
}

if(isset($message))
{
echo "$message";
}

I'm stuck and don't understand why this is not working. Thanks for your help in advance!

Nightfire
03-15-2004, 08:36 PM
Is anything being added/selected from the database? Are those query's being executed? If they're not, then how are you getting the variables $n and $e? Are they from the url or a form?

Sk8er9547
03-15-2004, 09:03 PM
Here is the full script.....


<?php
require_once('mysql/mysql_list.php');

function escape_data ($data)
{
global $dbc;
if(ini_get('magic_quotes_gpc'))
{
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
}

$message = NULL;
// These messages work fine
if(empty($_POST['name']))
{
$n = FALSE;
$message = "Please input your name!<br>";
}
else {
$n = escape_data($_POST['first_name']);
}

if(eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email']))))
{
$e = escape_data($_POST['email']);
}
else
{
$e = FALSE;
$message .= "Please input a valid E-Mail address!<br>";
}

if($n && $e)
{
$query = "SELECT id FROM newsletter WHERE email='$e'";
$result = @mysql_query($query);
if(mysql_num_rows($result) == 0)
{
$query = "INSERT INTO newsletter (id, name, email)
VALUES('$id', '$n', '$e')";
$result = @mysql_query($query);
if($result)
{
echo "Thanks";
exit();
}
// These are the messages that are not working
else
{
$message = "You could not be registered at this time. Please try again later.";
}
}
else
{
$message = "The E-Mail $email has already been entered into our database.";
}
mysql_close();
}

if(isset($message))
{
echo "$message";
}
?>

Nightfire
03-16-2004, 01:22 AM
Well thanks for that, but it still doesn't answer my questions. If the queries aren't being executed, then there's either a) something wrong with the query, or b) you're using the wrong variables, or c) you're using outdated code

If the queries are being executed, then that's a complete different story

ConfusedOfLife
03-16-2004, 09:10 AM
echo something in all your conditions and see if they work, as Nightfire said it should be something wrong with your queries, something that stops the flow of your script. It's not bad if you also posted your HTML form, you know, sometimes it happens we do some little mistakes in our form that we don't get anything in the PHP. No matter of how much experience you have, these little things happen!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum