-3

I have a page from a website that I took over a few years back. I am a novice on php and are more into Wordpress. Now the page is starting having problems and I get the above errors in the given lines.
This is the code:

1. $db = mysqli_connect("localhost", "vrvtnl_data", "eric") or die 
   ("fout1"); 
2. //mysqli_select_db("vrvtnl_data",$db) or die ("fout2"); 
3. function test($nummer,$week){ 
4. $sql = 'SELECT * FROM `vakantie` WHERE `tandarts` =' . 
5. $nummer . ''; 
6. $result = mysqli_real_query($sql); 
7. $test = mysqli_use_result($result, 0, "". $week .""); 
8. return $test; }

Can somebody help me, as said I am a novice with php, so detailed help ia appreciated.

Fastmarky
  • 1
  • 1
  • Did you read the error message? Did you look up the documentation for the functions you're using? What wasn't clear? – David Sep 24 '17 at 09:45
  • Your function behaves exactly like `mysql_real_escape_string`. If you typed in the error message within Google you would 100% found more than 10 solutions. You did a very good research. – cramopy Sep 24 '17 at 09:45

1 Answers1

2

You passing only one parameter (query), but you must pass two parameters (connection link and query).

bool mysqli_real_query ( mysqli $link , string $query )

Parameters:

  • link

Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

  • query

The query, as a string.

http://php.net/manual/en/mysqli.real-query.php

But in your situation you need mysqli_query.

Your code should look like:

$db = mysqli_connect("localhost", "vrvtnl_data", "eric") or die ("fout1"); 

function test($nummer, $week) {
    global $db;
    $sql = "SELECT * FROM `vakantie` WHERE `tandarts` = '$nummer'"; 
    $result = mysqli_query($db, $sql); 
    return $result ? mysqli_fetch_assoc($result) : []; 
}
Neodan
  • 5,154
  • 2
  • 27
  • 38
  • Thnx Neodan, for your complete answer. If i implement your code, the last line gives this warning: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given – Fastmarky Sep 24 '17 at 10:33
  • @Fastmarky sorry for bad previos answer. I updated my answer – Neodan Sep 24 '17 at 12:38