Hi everyone,
I've seen a few of these posts but none have solved my issue. I am an extreme newbie, if someone could tell me why I get this error (and what it means) I would be grateful.
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\cms\insert_record.php on line 22
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\cms\insert_record.php on line 25
Unable to query the database: .
Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\wamp\www\cms\insert_record.php on line 29
<?php
if(isset($_POST['title'])) {
$link = mysqli_connect('localhost', 'XXX, '', 'XXX');
if (mysqli_connect_errno()) {
echo '<p>Cannot connect to DB: ' . mysqli_connect_error() . '</p>';
}
} else {
$title = $_POST['title'];
$content = $_POST['content'];
$keywords = $_POST['keywords'];
$query = 'INSERT INTO `documents`
(`title`, `contents`, keywords`)
VALUES
(\'' . $title . '\', \'' . $content . '\', \'' . $keywords . '\')';
}
$result=mysqli_query($link, $query);
if (!$result) {
echo '<p>Unable to query the database: ' . mysqli_error($link) . ' .</p>';
} else {
echo '<p>Added!</p>';
}
mysqli_close($link);
?>
Thanks in advance, I've been at this one for hours. 🙂