I want to dynamically determine the data type of input values I am getting from my HTML input form.this will assist me to bind parameter values of data I am inserting into my database using PHP.
This information will assist me to determine the values of the string 'sss' in the code below for MySQL prepared statement, I want to create an insert data class and the input values can be of the type 'sdib' for the types string, double,integer,or Blob.
if($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param("sss", $first_name, $last_name, $email);
}
I have tried the code below and even tried some other codes in PHP manual that uses call_user_func_array()
in vain.
I understand input values from HTML forms are always strings.
// SECTION USING PREPARED STATEMENT IN INSERT QUERY
if ($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param("sss", $first_name, $last_name, $email);
}
//CODE SHOWING HOW I AM TRYING TO GET DATA TYPE OF HTML INPUT VALUES
if (gettype($v) === "string") {
return "s";
} elseif (gettype($v) === "float") {
return "d";
} elseif (gettype($v) === "integer") {
return "i";
} elseif (gettype($v) === "binary") {
return "b";
} else {
$e = '..could not establish data type';
$this->setError($e);
echo $e;
}
I want to be able to get datatype part 'sss' DYNAMICALLY from HTML input forms. the statement I want to construct is similar to this
$stmt->bind_param("sddsii", $first_name, $last_name, $email);