Я пытался преобразовать свой скрипт из mysql в mysqli, и во время этого процесса я получил следующую ошибку, перечисленную ниже.
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in on line 41
Warning: mysqli_error() expects exactly 1 parameter, 0 given in on line 43
Вот полный код ниже.
<?php
require_once ('./mysqli_connect.php'); // Connect to the db.
if (isset($_POST['submitted'])) {
// Query member data from the database and ready it for display
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT * FROM tags");
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error($mysqli);
}
// grab the tag
$tag = mysqli_real_escape_string($mysqli, $_POST['tag']);
// see if the tag already exists and potentially what the current count is
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT id, count, page FROM tags WHERE tag='$tag'");
//--if there is a row, that means the tag exists
if(mysqli_num_rows($dbc))
{
//--pull out the tag ID and the current count and increment by one.
$tag_info = mysqli_fetch_array($result);
$tag_info_id = $tag_info["id"];
$tag_info_count = $tag_info["count"] + 1;
//--update the table with the new count
$sql_update_cnt = "UPDATE tags SET count='$tag_info_count'
WHERE id='$tag_info_id'";
mysqli_query($sql_update_cnt);
echo "$tag now with $tag_info_count instances";
}
else
{
// tag is not there, so insert a new instance
$query = "INSERT INTO tags (tag, count) VALUES ('$tag', 1)";
if (!mysqli_query($query, $dbc))
{
die('Error: ' . mysqli_error());
}
echo "1 record added";
}
mysqli_close($dbc);
}
?>