我正在使用PHP来添加从HTML Web读取的值到PostgreSQL表,我不知道为什么值读取的值不会添加自身。我正在与pgadminiv合作。这是我的代码,希望有人可以帮助我。
<?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')";
?>
编辑:更改ID INT(6(无符号auto_increment主键,用于ID整数。
我解决了我的问题,我正在混合mySQL和postgressql代码。这是我的解决方案:
<?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();
?>