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

Dima
  • 27
  • 1
  • 8

2 Answers2

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 } ?>
B. Desai
  • 16,414
  • 5
  • 26
  • 47
  • I think you got the `php`'s opening and closing tag wrong – Carl Binalla Jun 13 '17 at 06:42
  • @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 – B. Desai Jun 13 '17 at 06:45
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}?>
Rahul
  • 2,374
  • 2
  • 9
  • 17