Click here to Skip to main content
15,887,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I do not get any data on an open page when doing echo, I am not sure if it is on the correct place, or doing something wrong

PHP
<pre><?php
  if ((isset($_POST['db'])) && ($_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 $url;
        
		$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:

I have put the echo on different places, and still empty page
Posted
Updated 16-Aug-22 20:13pm

1 solution

echo and print doesn't work in web environments: they are meant to output to a console attached to the app and there isn't one that the user can see in a web app: PHP Echo and Print Statements[^]
If you want to output stuff the user can see, it needs to be part of the response.
 
Share this answer
 

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