[postgis-users] php/postgresql trouble

Nicklas Avén nicklas.aven at jordogskog.no
Thu Mar 11 00:50:54 PST 2010


Hi
 
when you are using capitals in column name you have to use " around column name:
I am not good in php so I don't remember if it is ok to just double the " sign inside a string like
 
$sql = "INSERT INTO countries (""CountryID"", ""CountryName"", ""President"") VALUES .....
 
What I use to do is avoiding capitals in column names :-)
 
/Nicklas

2010-03-11 Linnet Kwamboka wrote:

hey guys,
>i dont know is anyone can help me i have been having trouble.
>i am using the follonwing code to do an INSERT query 
>
>
>
>
>
> 
>    
>          
>
> > if ($_POST['submit']) {
>     // attempt a connection
>     $dbh = pg_connect("host=localhost dbname=postgres user=postgres password=quash");
>      if (!$dbh) {
>         die("Error in connection: " . pg_last_error());
>     }
>     else{
>     echo "this was okay";
>     }
>    //exit; 
>    
>     // escape strings in input data
>     // $code = pg_escape_string($_POST['code']);
>//$name = pg_escape_string($_POST['name']);
>    //$president = pg_escape_string($_POST['president']);
>    
>     // execute query
>     $sql = "INSERT INTO countries (CountryID, CountryName, President) VALUES('{$_POST['code']}', '{$_POST['name']}', '{$_POST['president']}')";
>      $result = pg_query($dbh, $sql);
>     if (!$result) {
>         die("Error in SQL query: " . pg_last_error());
>     }
>    
>     echo "Data successfully inserted!";
>    
>     // free memory
>      pg_free_result($result);
>    
>     // close connection
>     pg_close($dbh);
> }
> ?>       
>
>    
>       Country code: 
  
>     

>      Country name: 
       
>       

>       President's name: 
       
>      

>     
>     
>   
>   
> 
>
>
>
>
>but i am getting the following error
>
> this was okay
>Warning: pg_query() [function.pg-query]: Query failed: ERROR: column "countryid" of relation "countries" does not exist LINE 1: INSERT INTO countries (CountryID, CountryName, President) VA... ^ in C:\xampp\htdocs\bongamate\weka.php on line 25
> Error in SQL query: ERROR: column "countryid" of relation "countries" does not exist LINE 1: INSERT INTO countries (CountryID, CountryName, President) VA... ^
>
>
>can anyone help me on this? thank you
> with regards geekmate!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20100311/981487a7/attachment.html>


More information about the postgis-users mailing list