First time trying to make a website and all other connections work excepts for this specific one. I am trying to connect to the server and update a non-specific variable. However, fails when I check if(!mysqli_stmt_prepare($stmt, $sql))
function addWeight($conn, $location, $weight){
require_once "dbh.inc.php";
$sql ="UPDATE userWeight SET ?=? WHERE userId = ?;";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../profile.php?error=sqlerror");
exit();
}
mysqli_stmt_bind_param($stmt, "ssi",$location,$weight, $_SESSION["userid"]);
mysqli_stmt_execute($stmt);
//$result = mysqli_query($conn, $sql);
$result =mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($result);
// close statment
mysqli_stmt_close($stmt);
}
where the function is called
<?php
if(isset($_POST["submit"])){
require_once "dbh.inc.php";
require_once "functions.inc.php";
session_start();
$weight = $_POST['Weight'];
// check if weight is full, if so shift all down and replace last
if($_SESSION['numWeight'] == 20){
echo "WEIGHT IS FULL";
}else{ // just add to next
$add = $_SESSION['numWeight']+1;
$location ="Weight";
$location .= strval($add);
addWeight($conn, $location, $weight);
}
}