I am new to php and trying to insert some values to my database table but query isn't working when I am passing values by php variables. The same query was working with static values.
I am making my database connection in init.php and the variable in there for same is $dbc.
<?php
require "init.php";
$mobile = "100004";
$email = "vikas4@web";
$password = "4444"
$stmt = mysqli_prepare($dbc, "INSERT INTO user_login (user_mobile, user_email, user_pwd) values(?, ?, ?)";
mysqli_stmt_bind_param($stmt, "sss", $mobile, $email, $password);
echo "after sql_query";
?>
For more detail, When I am replacing my $sql_query with below static code, it is inserting into database.
$sql_query = "INSERT INTO user_login (user_mobile, user_email, user_pwd) values('1000055', 'vikas55@web', '5555')";
$sql_queryyou will see that the query is invalid. The wrong way to solve this, is to add quotes around the values in the string. The right way is to use prepared statements and passing the values are parameters.