Jump to content

[SOLVED] why doesn't this work? (form/session/if/else statement)(well-explained!)(easycod


dsaba

Recommended Posts

this is driving me nuts, i've been at it for hours :(

basically the rundown of what i'm trying to do is this:

1. i generate a random code and store that code in a session

2. i have an html form that asks for that code

3. there is an if/else statement that display success statements if you type in the correct code or if you didn't type in the correct code

 

here is the code (the parent brackets are the ones that are farthest out, its better if you paste this code into a php editor to see the if/else statement more clearly)(sorry thats how I tab if/else statements)

 

<?php
session_start();
/////////////////////////////////////////////////////
srand((double)microtime()*1000000); 
$randomnumber = md5(rand(0,9999)); 
$code = substr($randomnumber, 17, 5);
$_SESSION['code'] = $code;
//////////////////////////////////////////////////////

$field = $_POST['field'];
$field_func = "hello";

/////////////////////////////////////////////////////////////////////////////////////////
if ($field != "")										{
if ($field == $_SESSION['code'])				{
if ($field_func == "hello")	{
echo "function = true";
echo '<br>';
echo "Entered: ";
echo $field;
echo '<br>';
echo "Session was: ";
echo $_SESSION['code'];
						}
else						{
echo "function = false";
echo '<br>';
echo "Entered: ";
echo $field;
echo '<br>';
echo "Session was: ";
echo $_SESSION['code'];
						}
											}
elseif ($field != $_SESSION['code'])			{
echo "field does not equal the session";
											}
													}
else													{
echo "Type in this code: ";
echo $_SESSION['code'];
echo '<br>';
echo '<form name="whatever" method="POST" action="new.php"><input name="field" type="text" class="form-field" size="30" maxlength="15" /><input type="submit" name="Submit" value="Submit" /></form>';
													}









?>

 

*EDIT- this code viewer in this forum fucks up my tabs so i took a picture :)

http://img338.imageshack.us/img338/8283/samplecodeih6.png

samplecodeih6dn8.png

 

 

 

############THE PROBLEM##########

No matter if you type the correct code in it always shows "field does not equal the session"

this is apparently not true!, please help - thanks

First question (Which may or not have any effect) before I look at the rest...where is $field defined?

 

Because unless you do:

 

<?php

$field = $_POST['field'];

?>

 

...You're asuming that register_globals is enabled wherever the script is running.

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.