I am having difficulty inserting into a database from the following html and php
Here is the html:
<body>
<form action="insert.php" method="post">
<div id="sgc">
<div id="logo">
Student Grade Checker App
</div>
<div>
<textarea class="display-input" id="input-text" rows="5" cols="35" name="input_text" placeholder="Enter the module names and marks separated by comma [put each mod>
</div>
<div>
<textarea class="display-output" id="output-text" rows="5" cols="35" readonly=1 placeholder="Results here..." value="">
</textarea>
</div>
<div>
<button class="sgcbutton-active" name="total_marks" onclick="verify();getTotal();">Total Marks</button>
</div>
<div>
<button class="sgcbutton-active" onclick="verify();getMaxMin();">Highest & Lowest Scoring Modules</button>
</div>
<div>
<button class="sgcbutton-active" onclick="verify();getSortedModules();">Sort Modules</button>
</div>
<div>
<button class="sgcbutton-active" onclick="verify();getClassification();">Classify Grade</button>
</div>
<div>
<button class="sgcbutton-active" onclick="verify();getAverage();">Overall Average</button>
</div>
<div>
<button class="sgcbutton-active" onclick="verify();getIndividualClassification();">Individual Module Classification</button>
</div>
<div>
<button class="sgcbutton-clear" onclick="clearText();">Clear</button>
</div>
</div>
</form>
</body>
The php code:
<?php
if (isset($_POST['total_marks'])){
$totalMarks = $_POST['total_marks'];}
$insertsql = "INSERT INTO total_marks (Module) VALUES('$totalMarks')";
$result = $conn->query($insertsql);
if (!$result) {
echo $conn->error;
}
?>
I am only working with the first button to get it working i will want to eventually insert the others too.
I am getting this error:
Fatal error: Uncaught Error: Call to a member function query() on null in /var/www/html/insert.php:9 Stack trace: #0 {main} thrown in /var/www/html/insert.php on line 9
My database connection is successful.
Any help is always appricated.