Я хочу вставить в SQL с помощью этой функции, но это не работает, любая идея, чтобы исправить этуКак исправить эту функцию в PHP
ошибка Warning: mysqli_query() ожидает параметр 1, чтобы быть MySQLi, нуль дано в C: \ WampServer \ www \ test.php в строке 29
<html>
<body>
<?php
$Connection = mysqli_connect('localhost', 'root', '', 'pytshqip');
$contact_method = 'aaaaa';
$form_data = array
(
'text' => $contact_method,
'from' => $contact_method,
'user_1' => $contact_method,
'user_2' => $contact_method,
'date' => time()
);
dbRowInsert('chat', $form_data);
function dbRowInsert($table_name, $form_data)
{
// retrieve the keys of the array (column titles)
$fields = array_keys($form_data);
// build the query
$sql = "INSERT INTO ".$table_name."
(`".implode('`,`', $fields)."`)
VALUES('".implode("','", $form_data)."')";
// run and return the query result resource
return mysqli_query($Connection, $sql);
}
?>
</body>
</html>
Здесь дата, какой тип. Он кажется целым .. –
Неопределенная переменная '$ Connection' в' dbRowInsert'. – Daan
переменная область видимости, вот и все. '$ Connection' определяется вне функции –