if statement with printing html

I have progressed with my code, and have now come across another problem. I am trying to make it so that it says if the form results are not empty echo a html code. I am not getting any errors when the code is executed, but I am not getting anything printed. The extract from the code is below.

$name = $_POST[‘name’];
$length = $_POST[‘length’];
$value = $_POST[‘value’];
if(!isset($name)) {
echo “”;
if(!isset($length)) {
$length ==“25”;
if(!isset($value)) {
$value =="";
} else {
echo ’


When I fill in the form on the previous page with data and it sends it to the above code, it returns and empty page.

All help is appreciated.

Well, I think your ELSE statement is the issue. If VALUE is not set you set it to “” then you leave without echoing anything

Presuming you want to echo the input line regardless of the value (empty or not). I would re-write it like the following:


<? $name = !empty($_POST['name']) ? $_POST['name'] : ''; $length = !empty($_POST['length']) ? $_POST['length']: '25'; $value = !empty($_POST['value']) ? $_POST['value'] : ''; echo ' ?>


I have used the Tertiary function (search this site, you will see that I love using this function for initializing variables). It is the same as


<? if ( !empty($_POST['name']) ) { $name = $_POST['name']; } else { $name = ''; } ?>


It’s much cleaner using the teritary function and it’s all done in one line. Also, it eliminates the [b]NOTICE: Undefined index… [/php] error.

Hope this helps.

Right, what I am trying to do is make the script get the results of what was posted, and use those result to make a new form (the html code).

I have set up an option so they can choose how many forms they have, so there may be between 1 & 20 lots of data to store.

I want it to work so that if only 3 forms are submited it only echos 3 forms not 20 with only 3 working.

I hope you understand what I am trying to do.

From the code above you could try elseif instead of several if statements.
//so on and so forth…

Sponsor our Newsletter | Privacy Policy | Terms of Service