i'm trying to insert values into a mysql table using inputs from another page using $_POST and a prepared statement. My understanding is that you need to use the bindParam function for each of the variables being inserted because you cant use variables in a mysql query.
My issue is that the bindParam function requires the length of the variable being binded and the variable's value is unknown because it is decided by the user input.
Do I have to create a variable for the string length of the variable I want to assign a Param to?
if(isset($_POST['name_input'])) {
$name = $_POST['name_input'];
$genre = $_POST['genre_input'];
$size = $_POST['size_input'];
$rating = $_POST['rating_input'];
$date = $_POST['date_input'];
}
if(!empty($name)) {
$addedQuery = $db->prepare(
"INSERT INTO `torrent_list` (`movie_name`,
`movie_genre`,`file_size`, `rating`,
`release_date`) VALUES (NULL, ':name', ':genre', ':size', ':rating',
':date')");
$addedQuery->bindValue(':name', $name, PDO::PARAM_STR);
$addedQuery->bindValue(':genre', $genre, PDO::PARAM_STR);
$addedQuery->bindValue(':size', $size, PDO::PARAM_STR);
$addedQuery->bindValue(':rating', $rating, PDO::PARAM_STR);
$addedQuery->bindValue(':date', $date, PDO::PARAM_STR);
$addedQuery->execute(
);
}
Thanks.