Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
Page coming up blank after I compile PHP and PostgreSQL

Problem

I am having a problem displaying the page after I compiled this code, but I cannot see what is wrong with it and I cannot debug due to it not appearing on the web.

PHP and PostgreSQL Code:

<?php       
    // Connecting, selecting database
    $dbconn = pg_connect("host=*****  port=*****
    dbname=***** user=***** password=*****")
    or die('Could not connect: ' . pg_last_error());

    //collect
    if(isset($_POST['search'])) {
        $searchq = $_POST['search'];
        $searchq = preg_replace("#[^0-9a-z]#i"."".$searchq);

    // Performing SQL query
    $query = "SELECT * FROM enumbers WHERE code LIKE '%$searchq%'") or die ("could not search!");
       $result = query($query);
    if($result = 0){
        $output = 'There is no such E-Number!'
    }else{
        while($row = mysql_fetch_array($query)) {
            $code = $row['code'];
            $name = $row['name'];
            $type = $row['type'];
            $vegan = $row['vegan'];

            $output .= '<div> '.vegan.' ';
            }
        }
    }
?>

The Form and Printing Code:

 <div id="tablebox">
    <!-- Search bar -->
    <p>Is It Vegan?</p>
    <form name="form1" method="post" action="searchEnumbers.php">
        <input name="search" type="text" size="30" maxlength="5" />
        <input name="submit" type="submit" value="Search" />
    </form>

    <?php
        print("$output");
    ?>
</div>

Update

I think the problem might be I'm using some MySQL code, but I cannot tell If I am.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are using mysql_fetch_array instead of postgres method. Please see the sample

    <?php 
    // Connecting, selecting database
    $dbconn = pg_connect("host=****  port=****
    dbname=**** user=**** password=****")
    or die('Could not connect: ' . pg_last_error());
     $output = '';

    //collect
    if(isset($_POST['search'])) {
        $searchq = $_POST['search'];
        // $searchq = preg_replace("#[^0-9a-z]#i"."".$searchq);

    // Performing SQL query
    $query = "SELECT * FROM enumbers WHERE code LIKE '%$searchq%'";
    $ret = pg_query($dbconn, $query);
   if(!$ret){
      echo pg_last_error($dbconn);
      exit;
   } 
   $output = '';
   while($row = pg_fetch_assoc($ret)){
            $code = $row['code'];
            print_r($row);
            $name = $row['name'];
            $type = $row['type'];
            $vegan = $row['vegan'];

            $output .= '<div> '.vegan.' ';
   }
}
   echo "Operation done successfully\n";
   pg_close($dbconn);

?>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda