Basically after clicking the submit button, I want a pop up box to pop up saying successful or fail, then clicking OK to confirm the message. At the moment i am getting a pop up box "undefined" followed by failed message pop up box. HELP PLEASE!
here is the script
<?php
include ('config.php');
if (isset($_POST['name'])) {
$name = "name";
$query = "INSERT INTO pop ('id','name') VALUES ('','$name')";
$result = mysql_query($query,$cn);
if ($result) {
echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
}
else
{
echo "<script type='text/javascript'>alert('failed!')</script>";
}
}
?>
<html>
<head>
</head>
<body>
<form action="" method="post">
Name:<input type="text" id="name" name="name"/>
<input type="submit" value="submit" name="submit" onclick="alert();"/>
</form>
</body>
This question is related to
php
javascript
Instead of using a submit button, try using a <button type="button">Submit</button>
You can then call a javascript function in the button, and after the alert popup is confirmed, you can manually submit the form with document.getElementById("form").submit(); ... so you'll need to name and id your form for that to work.
Source: Stackoverflow.com