postgresql error

Help with correcting error

Page 1 of 1

2 Replies - 2044 Views - Last Post: 05 March 2010 - 09:25 PM Rate Topic: -----

#1 mweav113  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 20-September 09

postgresql error

Posted 05 March 2010 - 07:42 PM

Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "and" LINE 1: select * from bid WHERE itemid= and sellerid= ORDER BY bidp... ^ in /home/spring-10/f2fDatabases/rweaver2/public_html/project/bidlist.php on line 27

Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL result resource in /home/spring-10/f2fDatabases/rweaver2/public_html/project/bidlist.php on line 29

<?php
        $result3=pg_query("select * from bid  WHERE itemid=$_REQUEST[itemid] and sellerid=$userid ORDER BY bidprice DESC ");
		//echo "select * from bid  WHERE itemid=$itemid and sellerid=$userid ORDER BY bidprice DESC ";
        $rows3=pg_num_rows($result3);
        if($rows3>0){
        $i3=1;
        while($fetch3=pg_fetch_array($result3 , null, PGSQL_ASSOC))
        { ?>


Could anyone tell me what is wrong with this code?

Thanks mweav113

Is This A Good Question/Topic? 0
  • +

Replies To: postgresql error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6053
  • View blog
  • Posts: 23,488
  • Joined: 23-August 08

Re: postgresql error

Posted 05 March 2010 - 09:24 PM

WHERE itemid= and sellerid= ORDER BY 

Looks like your values aren't set.

$_REQUEST[itemid]
should be
$_REQUEST['itemid']

Was This Post Helpful? 0
  • +
  • -

#3 MRJ  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 118
  • Joined: 13-October 07

Re: postgresql error

Posted 05 March 2010 - 09:25 PM

From the Error message you posted it looks like your request variables aren't getting included in the SQL statement and that's why it's failing.

I haven't really been doing much with PHP recently but I seem to remember that you can't use $_REQUEST calls inside strings. You could try:

 $result3=pg_query("select * from bid  WHERE itemid=" . $_REQUEST[itemid] . " and sellerid=$userid ORDER BY bidprice DESC ");



Plus make sure that the $user variable is set before you call the query

Also to make sure that this is the problem run it with fixed values once as a test of the SQL statement.



View Postmweav113, on 05 March 2010 - 08:42 PM, said:

Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "and" LINE 1: select * from bid WHERE itemid= and sellerid= ORDER BY bidp... ^ in /home/spring-10/f2fDatabases/rweaver2/public_html/project/bidlist.php on line 27

Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL result resource in /home/spring-10/f2fDatabases/rweaver2/public_html/project/bidlist.php on line 29

<?php
        $result3=pg_query("select * from bid  WHERE itemid=$_REQUEST[itemid] and sellerid=$userid ORDER BY bidprice DESC ");
		//echo "select * from bid  WHERE itemid=$itemid and sellerid=$userid ORDER BY bidprice DESC ";
        $rows3=pg_num_rows($result3);
        if($rows3>0){
        $i3=1;
        while($fetch3=pg_fetch_array($result3 , null, PGSQL_ASSOC))
        { ?>


Could anyone tell me what is wrong with this code?

Thanks mweav113

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1