/    Sign up×
Community /Pin to ProfileBookmark

Confused echo

I have the following problem. I have tested and tested and found identification of problem for showing different design. It is correct design without if code. But there is different design if I have code with IF:
if (!empty($_POST[‘lastname’]))
Why could be difference in design with or without IF sentence?

Code is the following:

[code=php]
else
{
if (!empty($_POST[‘lastname’]))
{
echo ‘<div class=clear></div>
<div class=”fl_left” style=”padding-left: 40px;”>
<ul class=”error”>’;
echo ‘<li>This <b>E-mail</b> is already in use. Please try another e-mail.</li>’;
echo ‘</ul>
</div>
<div class=clear></div>’;

}

}
[/code]

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@carlhNov 20.2006 — make sure the post variable name matches the name in the form you're sending it from, maybe try this?

also if you're doing a block of html you can turn off the php tags, doing just a small section probably won't make much difference but it can add up over the course of a program
[code=php]
else
{
if (isset($_POST['lastname'])) {
?>
<div class=clear></div>
<div class="fl_left" style="padding-left: 40px;">
<ul class="error">

<li>This <b>E-mail</b> is already in use. Please try another e-mail.</li>
</ul>
</div>
<div class=clear></div>
<?
}
}
[/code]


try it with and without something in the lastname field in your form and see how it goes
Copy linkTweet thisAlerts:
@toplisekauthorNov 21.2006 — I have again tested to find problem. There is included file for validation. Problem is that I would like to show this above code on other part like echo $error.

Can you advise me how to echo this above code on other part of page?

Currentlly is if code above page, but echo and shown error should be at the bottom.
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — Currentlly is if code above page, but echo and shown error should be at the bottom.[/QUOTE]That is because your output and code follow the same order (linear). Try to write your code alinearly and only send output once any logical/illogical section of code has already been executed.
Copy linkTweet thisAlerts:
@toplisekauthorNov 21.2006 — 
Can you advise me how to echo this above code on other part of page?
[/QUOTE]

Hello,

I do not understand your reply as I'm new to this. Can you inform me how to echo error with function or variable?
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — [code=php]function EchoError($error)
{
echo $error;
}[/code]
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — Hello,

I do not understand your reply as I'm new to this. Can you inform me how to echo error with function or variable?[/QUOTE]
Are you talking to yourself?
Copy linkTweet thisAlerts:
@toplisekauthorNov 21.2006 — How to store in variable all this above code?
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — How to store in variable all this above code?[/QUOTE][I]$variables[/I] are for holding things that are variable; they are not for storing code.
Copy linkTweet thisAlerts:
@toplisekauthorNov 21.2006 — Ok, I understand.

Can you help me with code how to perform function that it will echo above code and how to implement code in function?
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — perform function that it will echo above code[/QUOTE]You do not echo code. What exactly are you asking?
Copy linkTweet thisAlerts:
@toplisekauthorNov 21.2006 — IF sentence is performed (top of the page code), it will show (echo) message notification at the bottom of page with the following code:

{

echo '<div class=clear></div>

<div class="fl_left" style="padding-left: 40px;">

<ul class="error">';

echo '<li>This <b>E-mail</b> is already in use. Please try another e-mail.</li>';

echo '</ul>

</div>

<div class=clear></div>';

}
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — Run the following code and try to figure out how it works. Note that the section at the top does [B]not[/B] send any output:[code=php]<?php

# logic/illogic here
$confused = false;
if('toplisek is confused')
{
$confused = true;
}

# middle of the page here


# echo at end here
echo 'toplisek is'.($confused ? '' : ' not').' confused';

?>[/code]
Copy linkTweet thisAlerts:
@toplisekauthorNov 21.2006 — Hello,

thank you for suggestion. Just this. How to put correct code in ' ' if it is true value? there is echo ' ' ?
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — [code=php]<?php

# logic/illogic here
$confused = false;
if('toplisek is confused')
{
$confused = true;
}

# middle of the page here


# echo at end here
echo 'toplisek is ';
if($confused)
{
echo 'confused';
}
else
{
echo 'not confused';
}

?>[/code]

Or:
[code=php]<?php

# logic/illogic here
$confused = null;
if(empty($_GET["confused"]))
{
$confused = '$_GET["confused"] is empty or not set';
}

# middle of the page here


# echo at end here
if($confused)
{
echo $confused;
die;
}

# do more stuff
echo $_GET["confused"];

?>[/code]
In option 2 [I]$confused[/I] works as a boolean [B]as well as[/B] holding the message whereas in option one it really is a boolean.
Copy linkTweet thisAlerts:
@bokehNov 21.2006 — Also have a look at [URL=http://www.webdeveloper.com/forum/showpost.php?p=663023&postcount=4]this thread[/URL]. Notice how the logic section is at the top and the output section is at the bottom. Try to follow that model instead of echoing everything. This will give you a chance to backtrack if necessary.
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...