Re: Error with query

From: Christian Ramseyer <rc(at)networkz(dot)ch>
To: Helgi Örn Helgason <sacredeagle(at)gmail(dot)com>
Cc: PostgreSQL - newbie <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Error with query
Date: 2010-10-07 08:32:55
Message-ID: 4CAD85B7.5070803@networkz.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 10/7/10 10:26 AM, Christian Ramseyer wrote:
>>
>> $query = "INSERT INTO timmar(pack_date, pack_week, pack_day, pack_pts,
>> pack_name, pack_tidin, pack_tidut, pack_lunch) VALUES('" . $pack_date
>> . "', '" . $pack_week . "', '" . $pack_day . "', '" . $pack_pts . "',
>> '" . $pack_name . "', '" . $pack_tidin . "', '" . $pack_tidut . "', '"
>> . $pack_lunch . "')";
>> $result = pg_query($query);
>> if (!$result) {
>> $errormessage = pg_last_error();
>> echo "Error with query: " . $errormessage;
>> exit();
>> }

Or if you don't like to use prepared statement, you could still drop all
these string concatenations since PHP expands variables in single quotes
that are already in double quotes:

rc(at)asado-263:~ $ cat foo.php

<?php
$x = "blah";
echo "x = '$x'\n";
?>

rc(at)asado-263:~ $ php foo.php
x = 'blah'

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Jean-Yves F. Barbier 2010-10-07 08:52:45 log into a table
Previous Message Christian Ramseyer 2010-10-07 08:26:24 Re: Error with query