在将表单提交到数据库之前,我的代码没有执行我的JS函数

时间:2018-05-01 00:06:28

标签: javascript php onsubmit

在将数据提交到数据库之前,我在执行javascript代码时遇到问题 - processPhase8()。数据被发送到数据库,但JS没有被执行,所以"决定"没有显示在数据库上。任何帮助将不胜感激。编程新手。

单击提交按钮后,我希望我的JS功能进行一些评分并将结果发送到<h1 class="alert-heading" id="decide" name="decide"></h1>,以便if (isset($_POST["submit"))可以将$decide = mysqli_real_escape_string($connection, $_POST["decide"])发送到数据库:

// this is the javascript code I want to execute once the submit button is clicked before sending the form data to the database

function processPhase8()
{
    if(creditscore >= possibleScore) {
        _("decide").innerHTML="response1";
        return true;
    }
    else if( creditscore === possibleScore) {
        _("decide").innerHTML= "response2 "
        ;
        return true;
    }
    else {
        _("decide").innerHTML= "response3";
        return true;
    }
}
}

<?php
if(isset($_POST["submit"])) {
    $decide = mysqli_real_escape_string($connection, $_POST["decide"]);
    $query  = "INSERT INTO users(decide) VALUES('$decide')";
    mysqli_query($connection,  $query ); // connect DB and process query
    //create a variable to see if it went through
    $result =  mysqli_query($connection,  $query ); // assign variable

    if ($result) {
        echo "<p style=font-size:30px;>Hurray, It Works!</p>"; } // checking that the query worked
    } else {
        echo " it didn't work";
    }
?>

<head> 
<script src="signupmulti.js"> </script>
</head>
<html>
<form method="post" action="signup.php" id="multiphase" onsubmit="return processPhase8()" enctype="multipart/form-data">
    <div class="alert alert-success" role="alert">
        <h1 class="alert-heading" id="decide" name="decide"></h1>
    </div>
    <button name="submit" type="submit" class="btn btn-lg btn-default">Click here for a decision </button>
</form>
</html>

0 个答案:

没有答案