Jump to content

Recommended Posts

Hello all, I'm a basic coder 😀
I want to insert a line break in this code, after the {hobby:value} it gives me : syntax error, unexpected '>'

if($_POST['form']['hobby'] == '')
  $modUserEmailText = str_replace('{hobby:caption} : {hobby:value}', ''<br/>'',$modUserEmailText);


{hobby:caption} : {hobby:value} are placeholders in the sent email, since there are several of them, all I want is a line break between each.. and must end with $modUserEmailText);
is this possible to do?

{hobby:caption} : {hobby:value}
{age:caption} : {age:value}
{book:caption} : {book:value}

Thanks a million!

Link to comment
https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/
Share on other sites

Well, all I can really do is tell you about the problems you post here, and this current one is because you're typing two apostrophes in the place of one quotation mark.

If you still have problems after fixing that then we'll deal with them. But you'll have to describe them.

I've tried this, still no change, but does not give me errors

if($_POST['form']['hobby'] != '')
echo "<br />";
$modUserEmailText .= '{hobby:caption} : {hobby:value}';

This one gives me an error : syntax error, unexpected ','

if($_POST['form']['hobby'] != '')
$modUserEmailText .= '{hobby:caption} : {hobby:value}'."\r\n";

any thoughts?

7 hours ago, Sandra said:

This one gives me an error : syntax error, unexpected ','

if($_POST['form']['hobby'] != '')
$modUserEmailText .= '{hobby:caption} : {hobby:value}'."\r\n";

The error is complaining about a comma in the code. There is no comma in that code.

  • Haha 1

With most of these examples you are omitting blocks.  Here is a block:

{
   //Something
}

Many languages use the {} to denote a block.  There are others that use something different, or use indentation (most notably python), but PHP is not one of those languages.

Let's go back to an example you gave (Indentation mine):

 

if($_POST['form']['hobby'] != '')
    echo "<br />";
    $modUserEmailText .= '{hobby:caption} : {hobby:value}';

After your condition

 ($_POST['form']['hobby'] != '')

You do not have a start block.  So only the next line will be executed if the condition is true.  I don't think that is what you expect.    So you need a block around ALL the code that will execute if the condition is true:

if($_POST['form']['hobby'] != '') {
    echo "<br />";
    $modUserEmailText .= '{hobby:caption} : {hobby:value}';
}

 

Obviously you are not giving us real code or are giving us snippets of the code as the errors don't correlate to the code you've provided, but perhaps this explanation will help you out.  Just for completeness:

if (!empty($_POST['form']['hobby']) {
    echo "<br />";
    $modUserEmailText .= '{hobby:caption} : {hobby:value}'    
}

This would be the proper way to handle the condition you are checking for.  The problem with the code you presented, is that it will provide a runtime error if the $_POST['form']['hobby'] element does not exist.  For things like checkboxes, this is a common occurrence.  empty checks that the variable exists (isset) AND that it has a value  (!= ''');  You might also want to trim the value, as even a space would pass through your check and empty.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.