| 11:05 pm on Jul 27, 2007 (gmt 0)|
You are trying to access a variable before its set. Look into isset [uk2.php.net] and change this line:
<?php echo $error;?>
<?php echo (isset($error)? $error : '');?>
Basically you are echoing the value to the page before the variable exists. Hope that makes sense.
| 11:21 pm on Jul 27, 2007 (gmt 0)|
Is this correct? It's turning out funny in my text editor.
<?php echo (isset($error)? $error : ");?>
Is the " suposed to be there? Either way I'm getting errors.
| 12:29 am on Jul 28, 2007 (gmt 0)|
Yes, that is correct. That syntax is basically a "short if/then statement".
Basically, you could write it the same way by saying...
if ( isset( $error ) )
It does the same thing in the end; it's just a matter of how the statement is formatted.
The syntax of the shortened if statement goes as follows:
($variable)? "Variable is true!" : "Variable is false!";
where $variable can be anything from a simple variable to a complex expression in the same style as something in an if statement. The statement will return "Variable is true!" if $variable evaluates to true, and "Variable is false!" if $variable evaluates to false.
Generally this syntax is used in places such as this where you don't want to write a multi-line if/else block, and simply want either one phrase or the other returned.
Edit: on looking at it further, there was a syntax error in there.
Old: <?php echo (isset($error)? $error : ");?>
New: <?php echo (isset($error))? $error : "";?>
[edited by: WesleyC at 12:31 am (utc) on July 28, 2007]
| 12:46 am on Jul 28, 2007 (gmt 0)|
Thanks, that clears things up. I'm not getting errors anymore but when I leave the name filed blank, the the error from function validate_form() isn't getting over to $error.
The first if statement:
$valid = validate_form();
if ($valid === true)
$error = $valid;
either brings the input data to a display page or re-displays the form with errors, only it's not displaying the error.
I still can't find the trouble.
| 6:11 am on Jul 28, 2007 (gmt 0)|
WesleyC, there wasn`t an error in the code I posted, but there is in the new you posted. That would throw a parse error.
Its called a Ternary Operator [uk2.php.net].
| 3:40 pm on Jul 30, 2007 (gmt 0)|
There's a few downsides to having to alternate between languages several times a day...
Edit: Though I think your snippet accidentally used a single double quote instead of two single quotes...
[edited by: WesleyC at 3:42 pm (utc) on July 30, 2007]
| 6:23 pm on Jul 30, 2007 (gmt 0)|
No problem. It was two single quotes, but maybe looks different due to the board formatting.