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.
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();
?>