for some reason that i can't seem to find, i can't get my mysqli code to write in my database. The "echo $newUserResult." ".$fullName;" work fine. I am pretty new to coding and i have spent lot of time trying to troubleshoot this. I'm sorry for wasting your guys time but i just can't see why it doesn't work.
<----- Data Base Connection ----->
<?php
$serverName = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "stw";
$conn = mysqli_connect($serverName, $dbUsername, $dbPassword, $dbName);
if (!$conn){
die("Connection Failed: " . mysqli_connect_error());
}
<----- My Code ----->
<?php
if(isset($_POST["nameSubmit"])){
session_start();
$newUser = $_SESSION["newUser"];
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$fullName = $firstName." ".$lastName;
$fullNameLength = strlen($fullName);
require_once 'dbc-inc.php';
require_once 'functions-inc.php';
if(emptyNameInput($firstName, $lastName) !== false){
header("location: ../profile.php?error=Emptynameinput");
exit();
}
if(invalidNamelength($fullNameLength) !== false){
header("location: ../profile.php?error=invalidnamelength");
exit();
}
if(invalidName($firstName, $lastName) !== false){
header("location: ../profile.php?error=invalidname");
exit();
}
addName($conn, $newUser, $fullName);
}
else{
header("location: ../profile.php");
}
<----- addName Function ----->
function addName($conn, $newUser, $fullName){
$sql = "INSERT INTO users (unew, uname) VALUES (?, ?)";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("location: ../profile.php?error=namestmtfailed");
exit();
}
$newUserResult = $newUser + 1;
mysqli_stmt_bind_param($stmt, "is", $newUserResult, $fullName);
mysqli_stmt_execute($stmt);
echo $newUserResult." ".$fullName;
exit();
}