3

Please help me to understand syntax of concat following

i want following code inside echo to understand concate

1--> <div class="alert echo $_REQUEST['error_id'];?>"\>

I try following code but getting syntax error that there is two echo..

2--> echo "<div class=\"alert" . echo $_REQUEST['error_id']; . "\">";

where mistake is that i cant get it... and i want two answer both using single quote and double quote

EDIT

Thank @Rizier123 now it working but css is not working as i have apply in calss="alert"

while using following code its working fine <div class="alert echo $_REQUEST['error_id'];?>"\>

enter image description here

But after applying your code its not working..only text appear but background color is not comming nad boarder is also dissappear as below

enter image description here

class name is alert shows the status of login..

EDIT

Thanks again i just forget to put space after class name..

Vishnu S. Divetia
  • 305
  • 1
  • 2
  • 10

3 Answers3

3

You don't need to write echo and ; again!

So this should work:

//echo with double quotes
echo "<div class=\"alert" . $_REQUEST['error_id'] . "\">";        

//echo with single quotes
echo '<div class="alert' . $_REQUEST['error_id'] . '">';       

Maybe you need to add a space if your class name includes spaces!(..."alert "...)

Amin
  • 579
  • 7
  • 23
Rizier123
  • 58,877
  • 16
  • 101
  • 156
2

try this

echo '<div class=\"alert"' .  $_REQUEST['error_id'] . '">';
Ansyori
  • 2,807
  • 3
  • 29
  • 37
2

You can do either 2 ways

1. PHP in HTML

<div class="alert<?php echo $_REQUEST['error_id'];?>">

2. HTML in PHP

echo "<div class='alert". $_REQUEST['error_id'] ."'>";

Or you can also do like

echo "<div class=\"alert". $_REQUEST['error_id'] ."\">";
GautamD31
  • 28,552
  • 10
  • 64
  • 85