-1

I'm trying to show a submit button based on a logical statement using PHP and HTML, but I can't figure out the syntax.

if(isset($_POST['newSubmit'])){ 
    <input type="submit" name="newSubmit" id="newSubmit" value="Select" />;    
}

This doesn't seem to work. Do I need to use an echo statement?

3
  • 2
    Use echo, echo '<input type="submit" name="newSubmit" id="newSubmit" value="Select" /> '; Commented Jun 13, 2017 at 6:37
  • 1
    Use this <?php ..... if(isset($_POST['newSubmit'])){ ?> <input type="submit" name="newSubmit" id="newSubmit" value="Select" />; <?php } ?> Commented Jun 13, 2017 at 6:38
  • More info about writing html with php Commented Jun 13, 2017 at 6:38

2 Answers 2

3

You have to do echo in php or write input outside php

1) echo to display

<?php if(isset($_POST['newSubmit'])){ 
   echo '<input type="submit" name="newSubmit" id="newSubmit" value="Select" />';    
} ?>

2)write html Out side php

<?php if(isset($_POST['newSubmit'])){ ?>
    <input type="submit" name="newSubmit" id="newSubmit" value="Select" />
<?php } ?>
Sign up to request clarification or add additional context in comments.

2 Comments

I think you got the php's opening and closing tag wrong
@Swellar Its not wrong I have updated only solution from question provided guessing that php tag starting at beginning and closed at end of file.Which doest not stated here. BTW I have aded tags
0

When generating html in php you need to either use echo or enclose php tags

<?php
if(isset($_POST['newSubmit'])){ 
    echo '<input type="submit" name="newSubmit" id="newSubmit" value="Select" />';    
}
?>

or

<?php
if(isset($_POST['newSubmit'])){?> 
<input type="submit" name="newSubmit" id="newSubmit" value="Select" />    
<?php}?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.