How to add style whereby PHP

Hi everyone,
I’d like to add a paragraph in a particular location on a page.
I.e , if a user sends ‘1’ via a form, I’d like a certain div on my page to be added a paragraph (<p>1</p>)) else, I’d add another div a pararaph that says: <p>2</p>. I belive JS is suitable but I’d rather stick to PHP for the time being.
Could anyone help me with that?
Thanks a lot !

That’s simple enough, once you have your value from the form.

$valid = array('1', '2'); // Fill with valid values for the form input

if(in_array($_POST['number'], $valid)) { // Validate the input

    $number = htmlspecialchars($_POST['number']);   // you would probably get away without htmlspecialchars() here, but good practice to always

}
else {  //  Invalid input
   echo "Error!" ; // handle this as you wish
}

Then in your html:-

<p><?php echo $number ?></p>
3 Likes

Thanks a lot Sam

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.