Home > Mobile >  Issues calling php scripts in HTML
Issues calling php scripts in HTML

Time:11-01

I am running into a strange error on a website using multiple PHP scripts. For some reason, every submit button only calls the first PHP script defined rather than the one chosen. I know all of these scripts work and this issue started only recently. Here is the code in question:

<!DOCTYPE html>
<html>
<head>
    <title>Embed PHP in a .html File</title>
</head>
<body>
    <h2>POV</h2>
    
    <form action="index.php">
        <button type="gohome">Return to main form</button>
    </form>
    
    <h3>WIP Final results:</h3>
    <br>
    <?php
        include("showdatabasecontents.php");
    ?>
    
    <form method="post" action="clearFinal.php">
    <input type="submit" name="clearFinal" value="Clear Responses">
    
    <form method="post" action="resetFinal.php">
    <input type="submit" name="resetFinal" value="Reset ID Count">
        
    <h3>Students names</h3>
    <?php
        include("showdatabasecontent2.php");
    ?>
    
    <h3>Add a Student</h3>
    <form method="post" action="addstudent.php">
    Student Name : <input type="text" name="studentname"><br><br>
    <input type="submit" name="addstudent" value="Submit">
    </form>
    
    <h3>Delete a student</h3>
    <form method="post" action="connect.php">
    ID : <input type="text" name="id"><br><br>
    <input type="submit" name="removeStudent" value="Submit">
    <br>
    </form>
</body> 
</html>

I have tried changing some of the names for the buttons to make sure there was not a conflict but that did not make any different. Any info on this issue will help, thanks!

CodePudding user response:

try to add an id to each form. and change

<input type="submit" name="" value="">

to

<button type="button" onClick="test()">Submit</button>

example

<h3>Delete a student</h3>
<form id="deleteStudent" method="post" action="connect.php">
ID : <input type="text" name="id"><br><br>
<button type="button" onClick="test()">Submit</button>
<br>
</form>

last add javascript

<script>
    function tes(){
        document.getElementById('deleteStudent').submit()
        }
</script>

CodePudding user response:

You cannot have nested forms. Please close your forms properly and retry

CodePudding user response:

Found the issue, at the advice of Quentin, I used https://validator.w3.org/. I came to the conclusion based on the information I drew that I was missing a closing tag for two form elements. I would mark this as solved but stackoverflow won't let me for two days :(

  • Related