I'm trying to set up a simple database with Heroku/PGSQL. So far I've made a connection and created the table I want, but whenever I try and insert data to the table nothing happens.
For testing purposes, I'm using the code
$dbconn = pg_connect(pg_connection_string());
if (!$dbconn) {
echo "Database connection error. ";
}
else {
// Create table
$create="CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY NOT NULL,
gender CHAR(30),
age INT,
location CHAR(30),
timestamp CHAR(30)
)";
// Execute query
if (pg_query($dbconn,$create)) {
echo "Table users created successfully. ";
}
else {
echo "Error creating table. ";
}
}
function insert() {
$dbconn = pg_connect(pg_connection_string());
if (!$dbconn) {
echo "Database connection error 2. ";
}
else {
# Insert query
$insert = "INSERT INTO users (id, gender, age, location, timestamp) VALUE (1234, 'male', 99, 'UK', '31/05/2013')";
# Execute query
if (pg_query($dbconn,$insert)) {
echo "Data entered successfully. ";
}
else {
echo "Data entry unsuccessful. ";
}
}
}
When run, it returns "Table users created successfully." However, when I call the $$insert$$ function (I will later use this to insert different values into the table) it always returns unsuccessful.
What am I doing wrong?