Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:04:15+00:00 2026-06-15T10:04:15+00:00

What is wrong here? I get the table usertable fine. I’ve made sure that

  • 0

What is wrong here? I get the table usertable fine. I’ve made sure that the column name uid is there. But when I try to get uids from a query, nothing comes back. That is fine as the table is empty. However, my INSERT INTO command is not working because after the INSERT INTO, I still don’t have uids coming back. Using Postgres 9.1.5. Thanks!

$query = "SELECT * FROM information_schema.tables WHERE table_name = 'usertable';";
$result = pg_query($dbconn, $query);

if (pg_num_rows($result)) 
{
    echo "Table exists<br>";
    checkForUserRow();
}
else
{
   echo "Error on query, attempting to create table<br>";
   $sql = "CREATE TABLE usertable (uid integer PRIMARY KEY, sign varchar(255));";
   pg_query($dbconn, $sql) or die(pg_errormessage());

   $result = pg_query($dbconn,$query);
   if (pg_num_rows($result)) {
       echo "Table created<br>";
       checkForUserRow();
   }
}

pg_close($conn);

function checkForUserRow()
{
    $query = "SELECT uid FROM usertable WHERE uid = '123'";
    $result = pg_query($dbconn, $query);

if(pg_num_rows($result)) 
{
    echo "User DB row exists<br>";
}
else
{
    echo "User row does not exist - attempt to add user to table<br/>";

    $sql = "INSERT INTO usertable (uid) VALUES('123')";
    pg_query($dbconn, $sql);

    $result = pg_query($dbconn, $query);
    if (pg_num_rows($result)) 
    {
        echo "User successfully added!<br/>";
        }
    else
    {
        echo "User not added :(";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:04:16+00:00Added an answer on June 15, 2026 at 10:04 am

    Inside your function, you need to get the global $dbconn:

    function checkForUserRow()
    {
        global $dbconn;
        // everything else
    }
    

    This is because when you do pg_query($dbconn, $query); inside of the function, it’s using the local version of $dbconn, which doesn’t exist.

    You can also choose to pass in $dbconn as a parameter if you wish:

    function checkForUserRow($dbconn)
    {
        // global $dbconn; // Don't need this anymore.
        // everything else
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure what i am doing wrong here: mysql> use co_sysdev; Reading table information
Not sure whats wrong here the error report says line 9, but when I
I am not sure what I am doing wrong here, but I am having
What am I doing wrong here? I'm trying to get started with jQuery UI
How I get the Context? Am I doing something wrong here? This is my
I always get back Content Length Required 411, what am I doing wrong here?
There is probably something dumb I am doing wrong here. public function get_scores($id) {
What's wrong in here, I always get some nasty errors even if the same
I have a table called Users that has a column called deleted, a boolean
I can get table cell contents using following statement in Firefox, but no luck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.