i cant insert or update a record in postgres using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bluebird
    New Member
    • Sep 2006
    • 1

    i cant insert or update a record in postgres using PHP

    hi all

    i am trying to update a record , which is in postgres databse using PHP, it's not showing any error , but records are not updated.
    summary of the code given below
    <?php
    $db=pg_connect( 'user=postgres dbname=crm');
    $qry="update Customer SET dispostion='Rej ected' where phone='123456';
    $qry_res=pg_que ry($qry);
    print 'Affectd Rows '.pg_affected_r ows($qry);

    .......
    ?>

    i queried the Database , updation not reflected .

    any error in coding ??

    any help
    Thanks
    Bluebird
  • phpmaet
    New Member
    • Sep 2006
    • 27

    #2
    Hi
    check your connection details.

    Try this code,

    [PHP]<?
    // Connect to the Postgres Database

    $conn = pg_Connect("loc alhost", "5432", "", "", "test");
    if (!$conn) {echo "Connection error occurred.\n"; exit;}

    // Insert the form values into the database

    $result = pg_Exec($conn," INSERT INTO contacts VALUES ('$Name',
    '$Address','$Ci ty','$Email');" );

    // Select the values from database

    $result = pg_Exec($conn," SELECT cid, name, address, city, email FROM contacts WHERE cid = $ID");


    // Update the form values into the database

    $result = pg_Exec($conn," UPDATE contacts SET name='$Name',
    address='$Addre ss', city='$City',em ail='$Email' WHERE cid='$ID'");


    if (!$result) {echo "Query Error.\n"; exit;}

    pg_FreeResult($ result);

    // Close the connection
    pg_Close($conn) ;
    ?>[/PHP]

    Thanks

    Comment

    Working...