Search the Community
Showing results for tags 'PHP Java Script'.
-
Hello guys. I am new here. Well, I have some codes written in php. And I have several forms (insert, update etc.). And I have that confirmation box written in Java Script. The thing is next: when I click on submmit in my insert form the box shows up and when I click on OK the data is submmited in the database, but when I click on CANCLE the data is submmited too and I do not want that. Can anybody helps me please??? THIS IS MI INSERT CODE. <?php $con=mysqli_connect("localhost","root","",""); // Provjeri konekciju if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Varijable za sigurnost $naziv_artikla = mysqli_real_escape_string($con, $_POST['naziv_artikla']); $cijena_artikla = mysqli_real_escape_string($con, $_POST['cijena_artikla']); $na_stanju = mysqli_real_escape_string($con, $_POST['na_stanju']); // Sql upit za insert novih podataka u bazu $sql="INSERT INTO artikli (naziv_artikla, cijena_artikla, na_stanju) VALUES ('$naziv_artikla', '$cijena_artikla', '$na_stanju')"; // Provjera upita if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo header ("Location: index1.php"); mysqli_close($con); ?> THIS IS CONFIRMATION BOX (JAVA SCRIPT). <script> function myFunction() { var x; if (confirm("Da li želite da sačuvate promjene?") == true) { x = "You pressed OK!"; } else { x = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = x; } </script>