-
Ok I made some changes and still have erros.
Here's the form:
Code:
<form name="raffle" action="http://n2flash.com/raffle.php" method="post">
<input name="code" maxlength="25" size="20" type="text"><br>
<input value="Submit" type="submit">
</form>
Here's the modified code:
PHP Code:
<?php
$usercode = $_POST['code'];
$realcode = array('1', '2', '3', '4', '5');
$match = "false";
foreach ($realcode as $value)
{
if(strcasecmp($realcode[$value], $usercode) == 0)
{
$match = "true";
}
}
if($match == "true")
{
$to = "info@n2flash.com";
$subject = "Raffle Code";
$email = "info@n2flash.com";
$message = $_REQUEST['code'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{header( 'Location: http://www.n2flash.com/success.html' ) ; }
else
{header( 'Location: http://www.n2flash.com/error.html' ) ; }
}
else
{
header( 'Location: http://www.n2flash.com/error.html' ) ;
}
?>
Still producing the same error. submitting a blank form directs to success page with an email generated. Any value directs to error page with no email sent.
Mind boggling!
-
hmmm...I'm starting to suspect that it might be storing the numbers in your array as numbers and not as a string so try changing the if statement to this:
Code:
if ($realcode[$value] == $usercode)
if that makes it work then it is just the fact that your array has integer values and we were trying to string compare them.
-
Lol, this is making no sense to me but check this out...
Now with this code:
PHP Code:
<?php
$usercode = $_POST['code'];
$realcode = array('1', '2', '3', '4', '5');
$match = "false";
foreach ($realcode as $value)
{
if ($realcode[$value] == $usercode)
{
$match = "true";
}
}
if($match == "true")
{
$to = "info@n2flash.com";
$subject = "Raffle Code";
$email = "info@n2flash.com";
$message = $_REQUEST['code'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{header( 'Location: http://www.n2flash.com/success.html' ) ; }
else
{header( 'Location: http://www.n2flash.com/error.html' ) ; }
}
else
{
header( 'Location: http://www.n2flash.com/error.html' ) ;
}
?>
I submit nothing, and it's a sucess, with email.
I submit 1, it fails no email.
I submit 2, it works with an email???
Same for 3, 4 and 5. works and sends an email.
Just for giggles I submitted xx, and it failed.
I have no clue why, but I hope you do! lol
-
lol wtf that is weird....I just noticed that you have this:
Code:
if($sent)
{header( 'Location: http://www.n2flash.com/success.html' ) ; }
else
{header( 'Location: http://www.n2flash.com/error.html' ) ; }
Now I am just wondering if this is the same that you are doing for the else
part of the if($match == "true) statement. I don't think it would be making a problem, but with the luck we've been having who knows at this point...
-
Lol, restart! Start your code over again! Thats defiantly the sign to restart!! (Lol, jk theres probably an explanation, or not. I suggest restarting on it though)
Clean your code:
PHP Code:
<?php
$usercode = $_POST['code'];
$realcode = array('1', '2', '3', '4', '5');
$match = "false";
foreach ($realcode as $value) {
if (strcasecmp($realcode[$value], $usercode) == 0) {
$match = "true";
}
}
if ($match == "true") {
$to = "info@n2flash.com";
$subject = "Raffle Code";
$email = "info@n2flash.com";
$message = $_REQUEST['code'];
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers);
if ($sent) {
header('Location: http://www.n2flash.com/success.html');
} else {
header('Location: http://www.n2flash.com/error.html');
}
} else {
header('Location: http://www.n2flash.com/error.html');
}
?>
-
Well this is depressing, I changed the values to 5 digits, aa592.. bb592... etc and nothing works right.
Why do I even bother with php
>.<
-
OK I GOT IT!
Sorry I should have done this earlier, but I fired up my XAMPP and started testing it.
so now here is what I got:
Code:
<?php
$usercode = $_POST['code'];
$realcode = array('1', '2', '3', '4', '5');
$match = "false";
for($i = 0; $i < count($realcode); $i++)
{
if($realcode[$i] == $usercode)
{
$match = "true";
}
}
if($match == "true")
{
echo "Matched";
}
else
{
echo "did not match";
}
?>
Now just enter in your email stuff in the same section you were before.
I tested it on a couple numbers and it printed "Match" and also it does not match if you leave it blank now...
Hope this works for you now...
-
It works! The input is case sensitive but at this point WHO CARES! IT WORKS! lol
Here's the final code I tested:
PHP Code:
<?php
$usercode = $_POST['code'];
$realcode = array('1XB4', '2XB5', '3GG', '4778', '5');
$match = "false";
for($i = 0; $i < count($realcode); $i++)
{
if($realcode[$i] == $usercode)
{
$match = "true";
}
}
if($match == "true")
{
$to = "info@n2flash.com";
$subject = "Raffle Code";
$email = "info@n2flash.com";
$message = $_REQUEST['code'];
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers);
if ($sent) {
header('Location: http://www.n2flash.com/success.html');
} else {
header('Location: http://www.n2flash.com/error.html');
}
}
else
{
header('Location: http://www.n2flash.com/error.html');
}
?>
I will play with it some more tonight and see if I can understand more of how it's actually working. Thanks for all your help and prompt replies Moshambi!
-
Hey no problem man sorry it was such a drag at first! lol at least we got through it. Oh and btw to help out with the case sensitive issue just do this:
Code:
$usercode = strtoupper($_POST['code']);
that will convert it to all uppercase, if you want lowercase it is strtolower();
Also if you would like me to explain to you how each of the parts is working I would have no problem helping to try and help you understand it. Just let me know