Answer the question
In order to leave comments, you need to log in
Why is mysqli_query returning NULL?
Why does it return null?
$q = mysqli_query($connect, "SELECT * FROM `tabel` WHERE `served_id` = '{$served}' AND `receiver` = '{$receiver}'";
$query = mysqli_fetch_assoc($q);
Answer the question
In order to leave comments, you need to log in
right_answers = [-1, 1, 0]
print('Сколько будет 3+4-4*2, 9%4 и ~-1?')
while True:
user_answers = (int(input('Введите {} число:'.format(i))) for i in ('первое', 'второе', 'третье'))
equalities = [a == b for a, b in zip(right_answers, user_answers)]
if all(equalities):
print('Поздравляю, вы ответили верно!')
break
else:
if sum(equalities):
nums = ', '.join('{}-й'.format(n) for n, i in enumerate(equalities, start=1) if i)
print('Вы ответили верно на {} вопрос'.format(nums))
else:
print('Вы ответили не верно')
print('Попробуйте снова...')
print('Хорошая работа!!!')
input('Нажмите ENTER чтобы завершить')
You have specified the $query variable in mysqli_fetch_assoc but it looks like you need the $q variable
mysqli_query cannot return null, only true, false and an object of type mysqli_result.
mysqli_fetch_assoc will return null if there are no records matching your query.
PS In mysqli_fetch_assoc, pass the $q variable, not $query.
First, there is a bug in the code, there is no closing parenthesis at the end of mysqli_query().
And second, do this:
$q = mysqli_query($connect, "SELECT * FROM tabel WHERE served_id='".mysqli_real_escape_string($connect, $served)."' AND receiver='".mysqli_real_escape_string($connect, $receiver)."'") or die(mysqli_error($connect));
$query = mysqli_fetch_assoc($q) or die(mysqli_error($connect));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question