Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting an error on line 2,
Notice: Undefined index: db in C:\Mylinks\Kripto\Crypto\test.php on line 2


how can I fix it?

PHP
<pre><?php
  if($_POST['db'] == 'LifeCoinWatchDB')
	{
		$sql = mysqli_query($pdo,"SELECT * FROM api_currency ");

        $row = mysqli_fetch_array($pdo);
		
		$LIVECOINWATCH_API = $row['LIVECOINWATCH_API'];
		 
		$data = json_encode(array('currency' => 'USD', 'sort' => 'rank', 'order' => 'ascending', 'offset' => 0, 'meta' => false));

		$headers = array(
		"content-type: application/json",
		"x-api-key: LIVECOINWATCH_API",
		);

		$qs = http_build_query($data); // query string encode the parameters
 
		$url = "https://api.livecoinwatch.com/coins/list";
 
		$request = "{$url}?{$qs}"; // create the request URL
		
        echo $curl;
        
		$curl = curl_init(); // Get Curl resource
 
		curl_setopt_array($curl, array(
        CURLOPT_URL => $request,            // set the request URL
        CURLOPT_HTTPHEADER => $headers,     // set the headers 
        CURLOPT_RETURNTRANSFER => 1         // ask for raw response instead of bool
        )); 

       $response = curl_exec($curl); // Send the request, save the response

       curl_close($curl); // Close request     

        $decoded_json_lifecoinwatch = json_decode($response, true);// in index.php
		
		foreach($decoded_json_livecoinwatch['data'] as $livecoinwatch)// in index.html
		{

           $LIFECOINWATCH_code = $livecoinwatch['CODE'];
            $LIFECOINWATCH_name = $livecoinwatch['NAME'];
          
            $LIFECOINWATCH_name = htmlentities($LIFECOINWATCH_name, ENT_QUOTES, "UTF-8");		
			$checkSql = mysqli_query($pdo,"SELECT * FROM lcw_munt_lys WHERE CODE = '$LIFECOINWATCH_code' ") or die(mysqli_error($pdo));
            $checkSqlCount = mysqli_num_rows($checkSql);

            if($checkSqlCount > 0){
              
            }
            else{

				$insertSql = mysqli_query($pdo,"INSERT INTO lcw_munt_lys (CODE, NAME) VALUES('$LIFECOINWATCH_code', '$LIFECOINWATCH_name')") or die(mysqli_error($pdo));
			}
		}
	}
?>


What I have tried:

Did try
if  isset(($_POST['db'] == 'LifeCoinWatchDB'))


but then get this error

Parse error: syntax error, unexpected 'isset' (T_ISSET), expecting '(' in C:\Mylinks\Kripto\Crypto\test.php on line 2
Posted
Updated 16-Aug-22 18:56pm
v2

1 solution

Your POST data does not include an element named db.

Maybe you want something like

PHP
if ((isset($_POST['db'])) && ($_POST['db'] == 'LifeCoinWatchDB'))
  {
  .. .. ..
 
Share this answer
 
Comments
Odiez Bez 17-Aug-22 1:42am    
Thank you, no more error, will open new qestion for other problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900