Answer the question
In order to leave comments, you need to log in
Why do I get a connection error when querying SQL through the body of a PHP function?
I am suffering with such a problem: I need to get the value of this radio when clicking on the radio and pass it to the SQL query. In JS, I am getting a value.
$("input[name='select_account']").on('click', function () {
var x = $("input[name='select_account']:checked").val();
})
function sql_query($user_id) {
$query = 'select * from users WHERE id='.$user_id.';';
$query_result = mysqli_query($connection, $query);
if(!$query_result) {
die('Query failed'.mysqli_error());
} else {
echo ('Complete');
}
return $query_result;
}
Answer the question
In order to leave comments, you need to log in
PHP's main problem is that all online textbooks contain horror from the last century. And the saddest thing is that users of the AUser0 type repeat it mindlessly.
Here is the correct way:
function get_user($connection, $user_id) {
$stmt = $connection->prepare('select * from users WHERE id=?');
$stmt->bind_param("s", $user_id);
$stmt->execute();
return $stmt->get_result()->fetch_assoc();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question