I'm trying to make a javascript alert box popup inside some PHP code.
<html>
<body>
<a href=http://localhost/myPage/Index.html><button type=“button” />HOME</button></a>
<br><br>
<form name="SaveNewMember" method="post" >
Add New Member <br><br>
Member ID <input type="text" name="ID" value="">
<br>
Member Name <input type="text" name="name" value="">
<br><br>
<input type="reset" style="height:50px; width:80px" value="CLEAR ">
<input type="submit" value="ADD" style="height:50px; width:80px" action="<?php storeMemberData();?>">
</form>
<?php
function storeMemberData()
{
if((isset($_POST["ID"]))&(isset($_POST["name"])))
{
$newID = $_POST["ID"];
$newName = $_POST["name"];
if((strlen($newID)==5)&(strlen($newName)>=6))
{
$con=mysqli_connect("localhost","root","","membersdb");
mysqli_query($con,"INSERT INTO members
(ID,Name)
VALUES ('$newID','$newName')");
// Echo result
echo '<script type="text/javascript"> alert("Successful log"); </script>';
}
else
{
echo "<script type=\"text/javascript\">";
echo "alert(\"Invalid please try again.\")";
echo "</script>";
}
}
}
?>
I have two examples in there. Neither one works. The rest of the code is executing OK (via a submit button on a form). What gets printed to the webpage after submitting is literally the text
alert("Invalid please try again.")">
Any help appreciated, it must be something stupid and basic I'm doing wrong.
EDIT : In trying to keep the question brief I didn't print all my code. That was obviously wrong. Have updated the above to include the html form data above the php code too. This is the complete code.
And this is what prints on my page when it is run (reputation too low to add images)