Miss_Jones Posted April 19, 2012 Share Posted April 19, 2012 Hello I have not been able to find my answer anywhere else, so now i post it here: <html> <body> <p></p> </body> </html> <?php $var = 'Some text here!' ?> My questions is now: How do i get the text in the PHP variable into the HTML paragraph text? The code is on the same page Thanks in advance Jones Quote Link to comment https://forums.phpfreaks.com/topic/261232-help-with-html-and-php-integration/ Share on other sites More sharing options...
Drummin Posted April 19, 2012 Share Posted April 19, 2012 The page need to have php extension, iie. index.php Variables, i.e. $var are available below where they are defined. <?php $var = 'Some text here!' ?> <html> <body> <p><?php echo $var; ?></p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/261232-help-with-html-and-php-integration/#findComment-1338670 Share on other sites More sharing options...
Miss_Jones Posted April 19, 2012 Author Share Posted April 19, 2012 But what do i do if i want to change the variable again under the html code? Quote Link to comment https://forums.phpfreaks.com/topic/261232-help-with-html-and-php-integration/#findComment-1338675 Share on other sites More sharing options...
Miss_Jones Posted April 19, 2012 Author Share Posted April 19, 2012 Like this? <?php $var = 'Some text here!' ?> <html> <body> <form> <h5>Firstname:</h5> <input type="text"> <input type="submit" Value="Click me!"><p><?php echo $var; ?></p> </form> </body> </html> And then i want to change the text in the paragraph when the submit button is clicked Quote Link to comment https://forums.phpfreaks.com/topic/261232-help-with-html-and-php-integration/#findComment-1338678 Share on other sites More sharing options...
Drummin Posted April 19, 2012 Share Posted April 19, 2012 <?php $var = "Some text here!"; if (isset($_POST['Clickme'])){ $var = "Some NEW text here!"; } ?> <html> <body> <form> <h5>Firstname:</h5> <input type="text"> <input type="submit" name="Clickme" Value="Click me!"><p><?php echo $var; ?></p> </form> </body> </html> Edit: if (isset($_POST['Clickme'])) Ya, I just woke up. Quote Link to comment https://forums.phpfreaks.com/topic/261232-help-with-html-and-php-integration/#findComment-1338763 Share on other sites More sharing options...
algidDes702 Posted April 19, 2012 Share Posted April 19, 2012 Small change for above, minor detail. Just so you know Miss_Jones, PHP variables are case sensitive and as Drummin stated, php scripts run and process from top to bottom not bottom to top. <?php $var = "Some text here!"; if (isset($_POST['Clickme'])){ //here the original post had a lowercase "c", below the value of the button was "Clickme" not "clickme". I changed this line to match form $var = "Some NEW text here!"; } ?> <html> <body> <form> <h5>Firstname:</h5> <input type="text"> <input type="submit" name="Clickme" Value="Click me!"><p><?php echo $var; ?></p> </form> </body> </html> Hope the responses here helped your question Quote Link to comment https://forums.phpfreaks.com/topic/261232-help-with-html-and-php-integration/#findComment-1338764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.