-2
What can I do to fix this? I did some research, but I couldn’t understand what I’m doing wrong, my knowledge is basic in the subject. I bought an application that came old MSQL that no longer worked on PHP7, I’m trying to update.
Warning: mysqli_query() expects at least 2 Parameters, 1 Given in /Storage/ssd1/664/11665664/public_html/news/api.php on line 23
Warning: mysqli_query() expects at least 2 Parameters, 1 Given in /Storage/ssd1/664/11665664/public_html/news/api.php on line 32
Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, null Given in /Storage/ssd1/664/11665664/public_html/news/api.php on line 55 []
<?php
$servername = "localhost";
$database = "id11665664_admin";
$username = "id11665664_lincoln";
$password = "157abc";
// Create connection
$mysqli = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$mysqli) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
mysqli_close($mysqli);
?>
<?php
mysqli_query("SET NAMES 'utf8'");
//mysql_query('SET CHARACTER SET utf8');
if(isset($_GET['cat_id']))
{
//$query="SELECT * FROM tbl_news_category WHERE cid='".$_GET['cat_id']."' ORDER BY tbl_news_category.cid DESC";
//$resouter = mysql_query($query);
$query="SELECT * FROM tbl_news_category c,tbl_news n WHERE c.cid=n.cat_id and c.cid='".$_GET['cat_id']."' ORDER BY n.nid DESC";
$resouter = mysqli_query($query);
}
else if(isset($_GET['latest_news']))
{
$limit=$_GET['latest_news'];
$query="SELECT * FROM tbl_news_category c,tbl_news n WHERE c.cid=n.cat_id ORDER BY n.nid DESC LIMIT $limit";
$resouter = mysqli_query($query);
}
else if(isset($_GET['apps_details']))
{
$query="SELECT * FROM tbl_settings WHERE id='1'";
$resouter = mysqli_query($query);
}
else
{
$query="SELECT * FROM tbl_news_category ORDER BY cid DESC";
$resouter = mysqli_query($query);
}
$set = array();
$total_records = mysqli_num_rows($resouter);
if($total_records >= 1){
while ($link = mysqli_fetch_array($resouter, MYSQLI_ASSOC)){
$set['NewsApp'][] = $link;
}
}
echo $val= str_replace('\\/', '/', json_encode($set));
?>
if it is mysqli, correct the title of your question
– Ricardo Pontual
sorry, I didn’t notice the typo
– Lincoln Moreira
There are some errors with your code. You barely open the database connection and then close it. All following calls to
mysqli_close($mysqli);
will give error. As for the alerts, this is the signature ofmysqli_query
mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] ) : mixed
, in the first parameter pass the reference to the BD connection you obtained withmysqli_connect
. As an example one of your queries would look like this:$resouter = mysqli_query($mysqli, $query);
– Augusto Vasques