I have two pieces of code. Can you please tell me which one is correct and more secure?
<input type="text" class="form-control contact__form-control" placeholder="Your Name *" id="name" value="<?php echo htmlspecialchars ($name); ?>">
<?php echo "<span class='text-danger'>$nameError</span>";?>
or
<input type="text" class="form-control contact__form-control" placeholder="Your Name *" id="name" value="<?php echo htmlspecialchars ($name); ?>">
<?php echo htmlspecialchars ("<span class='text- danger'>$nameError</span>");?>
I have seen everyone to use the 1st one but i read that in PHP when you echo something its good to add htmlspecialchars for security reason. So i am wondering if the second piece of code is correct. Will the bootstrap alert class will work after the htmlspecialchars