Jump to content

Help with html and php integration


Miss_Jones

Recommended Posts

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?  :confused:

The code is on the same page  ;)

 

Thanks in advance  :D

Jones

Link to comment
Share on other sites

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  :D

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.