Reputation: 13
Every time I insert something into the second column in the database (uname) it ends up being 0. I debugged it and it has the correct text in php. Even if I hard code a value like "joe" it still inserts 0 in MySQL. The column is varchar(16). I also tried type Text. Here is the code:
<?php
$con = mysqli_connect("localhost", "user", "pw", "db");
$name = $_POST["name"];
$age = $_POST["age"];
$enteredUsername = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (name, uname, age, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $enteredUsername, $age, $password);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
?>
Upvotes: 1
Views: 87
Reputation: 5991
Change your bind parameters from int (i
) to string (s
):
mysqli_stmt_bind_param($statement, "ssis", $name, $enteredUsername, $age, $password);
Upvotes: 1