×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how can i insert data into a table in postgresql database

how can i insert data into a table in postgresql database

how can i insert data into a table in postgresql database

(OP)
I used this code after debuging to insert data in a table but the data from the form is not inserted. Please any idea why:

<?php
if($_REQUEST['criteriaid'] && $_REQUEST['domainid'] && $_REQUEST['criterianame'] && $_REQUEST['upperlimit'] && $_REQUEST['lowerlimit'] && $_REQUEST['range'] && $_REQUEST['unit'])// Check to see if All of the Fields were Filled Out
{
  pg_connect("host=138.250.104.227 dbname=rftDatabase user=globus password=globususer); // Connect to the Database
  $query = sprintf("INSERT INTO "Criteria_Parameters" VALUES ('%s','%s','%s' ,'%s','%s','%s','%s')",$_REQUEST['criteriaid'], $_REQUEST['domainid'], $_REQUEST['criterianame'],
  $_REQUEST['upperlimit'], $_REQUEST['lowerlimit'], $_REQUEST['range'], $_REQUEST['unit']); // Form the Query
/* Quick Lesson on Sprintf:
 * Sprintf Will take a string and format it. In this case I use %s which means that the Next parameter will be A string, and It
 * Should be put into wherever the %s is. The parameters will fill the %s's respectively
 */
  echo $query;
  // Uncomment the previous line to see what $query Contains. Everything that follows is just some simple error checking.
  $query = pg_query($query);
  if($query)
    echo "You have successfully added a record to the database!";
  else
    echo "Some Error Occured! ".pg_last_error();
}
else{ // If we dont have all of the fields, show the form
?>
<form METHOD="POST" ACTION="<?php echo $_SERVER['PHP_SELF']; ?>">
Criteria ID: <input type="text" name="criteriaid" />
Domain ID: <input type="text" name="domainid" />
Criteria Name: <input type="text" name="criterianame" />
Upper Limit: <input type="text" name="upperlimit" />
Lower Limit: <input type="text" name="lowerlimit" />
Range: <input type="text" name="range" />
Unit: <input type="text" name="unit" />
<input type="submit" />
</form>
<?php
   }

globus user has privilege to create database but does not have priviledge to create users. globus is not a superuser and cannot update catalogs. Could that be the reason why the data is not inserting.

Kind regards
Gokop

RE: how can i insert data into a table in postgresql database

Do you get an error?
Which?
Did you look into the logfiles?
Did you try to use the result of "echo $query" in the psql-frontend to insert the data as user globus?

don't visit my homepage: http://home.arcor.de/hirnstrom/bewerbung

RE: how can i insert data into a table in postgresql database

(OP)
Thanks Stefanwagner,

No error. 'eho $query' outputs the result of the data enter in the form as globus. However, this data is not inserted in the table. Another problem now is that when I changed the name to insert2.php, it does not recognise it but is still refering to insert.php, the old name.

Do you mean I should go to the client side and insert data from command prompt as globus user?

Regards
Gokop

RE: how can i insert data into a table in postgresql database

Yes, to verify permission, and to verify the statement.

Do you have some logfiles (postgresql, webserver)?
Which system is running postgresql?

don't visit my homepage: http://home.arcor.de/hirnstrom/bewerbung

RE: how can i insert data into a table in postgresql database

(OP)
Yes I have logfile in postgresql. Not sure of webserver.

This is the reason /opt/pgsql/logfile infomation:

LOG:  database system was shut down at 2007-12-12 13:24:47 GMT
LOG:  checkpoint record is at 0/CDDA90
LOG:  redo record is at 0/CDDA90; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 392899; next OID: 17339
LOG:  database system is ready

Regards
Gokop

RE: how can i insert data into a table in postgresql database

(OP)
Sorry I mean the recent /opt/pgsql/logfile
LOG:  database system was shut down at 2007-12-12 13:24:47 GMT
LOG:  checkpoint record is at 0/CDDA90
LOG:  redo record is at 0/CDDA90; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 392899; next OID: 17339
LOG:  database system is ready

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close