Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i insert data into a table in postgresql database 1

Status
Not open for further replies.

gglgokop1704

Programmer
Aug 9, 2007
54
GB
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top