Notifications with PHP

7

Hi, guys, how do I get an alert when the https request does not find the identification in a database by using an api rest? What I am doing is looking for an ID when it is found, it shows me on a table that information also a pdf, but when it is not found it shows me the table and the empty pdf (I tested by console returns a null) what I want is to block that table and the pdf and only show me an alert "Identification does not exist". Thanks for your reply.

PHP code:

if (isset($_POST['submit'])) {
$ruc=$_POST['ruc'];


$url = 'https://......'.$ruc;
$json = file_get_contents($url);
$datos = json_decode($json,true);

$rucs=$datos["NUMERO_RUC"];
echo'<br>';
echo'<div class="c">';
    echo '<table class="table">'
    .'<tr style="text-align:center">'
    .'<td style="background:#EEE"><b>Número de ruc</b></td>'
    .'<td style="background:#EEE"><b>PDF</b></td>'
echo '<tr style="text-align: center">'
        .'<td>' . $rucs. '</td>'
        .'<td>' . '<a href="pdf/pdf.php">PDF</a>'. '</td>'
echo '</table>';
echo'</div>';
}
    
asked by Andres 08.10.2018 в 02:07
source

1 answer

1

You can evaluate if there exists $ rucs, if the table exists, if it does not exist write the javascript code that sends an alert (), or whatever you want, like this:

if (isset($_POST['submit'])) {
$ruc=$_POST['ruc'];


$url = 'https://......'.$ruc;
$json = file_get_contents($url);
$datos = json_decode($json,true);

$rucs=$datos["NUMERO_RUC"];

if(!$rucs){
  echo '<script>alert("No se ha encontrado el identificador")</script>';
}else{
  echo'<br>';
  echo'<div class="c">';
  echo '<table class="table">'
    .'<tr style="text-align:center">'
    .'<td style="background:#EEE"><b>Número de ruc</b></td>'
    .'<td style="background:#EEE"><b>PDF</b></td>'
  echo '<tr style="text-align: center">'
    .'<td>' . $rucs. '</td>'
    .'<td>' . '<a href="pdf/pdf.php">PDF</a>'. '</td>'
  echo '</table>';
  echo'</div>';
  }
}
    
answered by 28.11.2018 в 17:23