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

173
Vistas
Unable to add values to postgreSQL

I'm working with php to add values read from a html web to a postgreSQL table, and I don't know why the value read doesn't add itself to the table. I'm working with pgAdminIV. Here is my code, hope someone could help me.

 <?php

  $mysqli=pg_connect("host=XXXXX.cim0cltex61z.us-west-2.rds.amazonaws.com port=5432 dbname=footplsseat user=footplsseat passsword=XXXXXXXX");
  $email= $_POST['email'];

  if (!$mysqli){
    echo "Connection failed";
  }
  else{
    echo "Succesfully connected";
  }

  $sql = "CREATE TABLE IF NOT EXISTS testportal (
  id INT, 
  email char(50)
 )";

 $query = "INSERT INTO testportal (email) VALUES ('$email')";

?>

EDIT: change id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, for id integer.

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

0

I solved my problem, I was mixing mySQL and postgresSQL code. Here is my solution:

<?php

$mysqli=pg_connect("host=XXXXX.cim0cltex61z.us-west-2.rds.amazonaws.com port=5432 dbname=footplsseat user=footplsseat password=XXXXXX");
$email = pg_escape_string($_POST['email']); 
$query = "INSERT INTO testportal(email) VALUES('" . $email . "')"; 
$result = pg_query($query); 
if (!$result) { 
    $errormessage = pg_last_error(); 
    echo "Error with query: " . $errormessage; 
    exit(); 
 } 
 printf ("These values were inserted into the database - %s", $email); 
 pg_close(); 

?> 
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