HTML:
<form action="?" method = "post" >
<button type="submit" class="btn btn-default btn-lg" name = "submit" value = 'Submit' >Register</button>
</form>
PHP:
<?php
if(isset($_POST['submit'])){
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
}
?>
The alerts don't come out when I click the button. The PHP does run if they're not enclosed within the 'if' statement.
You have to close If tag.
<?php
if(isset($_POST['submit'])){
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
}
?>
<?php
if(isset($_POST['submit'])){
?>
<script>alert('message successfully sent');</script>
<?php
}
?>
<form method="post" >
<input type="submit" class="btn btn-default btn-lg" name="submit" value="Register" >
</form>
Error is there is no closing tag for if
function
on here if(isset($_POST['submit'])){
and if your php code is inside same page then form action should be action="#"
else if your php code inside another file action
should be action="new_oage.php"
So code should be
<?php
if(isset($_POST['submit']))
{
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
} //Missing
?>
you might want to change your if condition...because you have no input field in form
if($_SERVER["REQUEST_METHOD"] == "POST"){
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.