1 Replies - 415 Views - Last Post: 13 April 2016 - 07:59 PM

#1 pidgeonpancakes   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 10-August 11

Cannot use PHP script to write to a specific space in my SHTML file

Posted 13 April 2016 - 07:46 PM

I am trying to write something that displays the text "Dave Jones" in the div class "someone" in my SHTML file from an external PHP file. It should do this on loading the SHTML page initially but if someone submits a name from the form the text "Dave Jones" is replaced with the name submitted from the form using the same PHP file.

Things I can't figure out:
1. How do I target the div to accept the data from the PHP file?
2. What can I use as an if() condition in the PHP file when the submit button is used from the form?

This is all very confusing for me.....

Bit of the SHTML code:
  <b><u>Best Customer of the Week!</u></b>
  <br>
  <div class="somename">
    <?php include('name.php');?>
  </div>  
  <br><br>
  Psssssss......
  <br>
  If you want to be the best customer of the week just enter your name here
  and click 'I'm the best customer!':
  <br>
  <form role="form" method="post" action="name.php">
  Your Name: <input type="text" name="yourname">
  <input type="submit" value="I'm the best customer!">
  </form>



My incomplete PHP code:
<?php
  
echo ("<p>Dave Jones</p>");

if () {
  $name = $_POST['yourname'];
  echo ("<p>$name</p>");
}

?>



Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot use PHP script to write to a specific space in my SHTML file

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2542
  • View blog
  • Posts: 10,184
  • Joined: 03-December 12

Re: Cannot use PHP script to write to a specific space in my SHTML file

Posted 13 April 2016 - 07:59 PM

You don't use shtml with included php for one thing.

How are you learning php if you can't answer this question?

Quote

2. What can I use as an if() condition in the PHP file when the submit button is used from the form?

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1