Jump to content

Recommended Posts


Yesterday, I decided I want to learn a little programming........ I built a development host, Fedora Core6 + Apache + Postgresql-8.1.6-1 + PHP-5.1.6-3.3.  I created a database and a table and columns and put data in the columns.



Created a simple page with a form:

<form action="http://192.168.1.39/tests/postgres2.php" method=post>
postgresql2
<br>
Enter Users name
<input type=text name=data>
<br>
<input type=submit value="Search database">
</form>


But I think my syntax is incorrect in my "postgres2.php" script, specifically this line:

$sql="SELECT * FROM phones WHERE people = '" . $data . "'"; 




If I swap out  = '" . $data . "'";  with a the name of a person from "people" column,

$sql="SELECT * FROM phones WHERE people = 'Bill’   

The script runs fine and provides me with the expected output.



I tried 

$sql="SELECT * FROM phones WHERE people = '" . $data . "'"; 
print $sql;

This output is generated on the web page:

SELECT * FROM phones WHERE people = ''

And thats why I think I have a sytntax error in that line.  I just can’t figure it out, I tried playing with the quotes. Its  probably something fundamental that I just don’t understand yet.

Im open to Any Suggestions at this point :-)

Thanks!



Link to comment
https://forums.phpfreaks.com/topic/35541-select-syntax-incorrect-for-where/
Share on other sites

Hi!

First, you say you "think" the error is in that line.. the first step is to be sure that the error is in that line.  You should be checking all your queries for errors, and printing out the error message where there is one, using pg_last_error() or pg_result_error().

In this line here:

[code=php:0]$sql="SELECT * FROM phones WHERE people = 'Bill’    [/code]

the quoting is incorrect.  You should be using ' and not ` or ’ for all your quoting of string values.  For quoting column names you can use ", but I don't think you need that here.

Anyway, try checking the error messages as I mentioned above.  That will give you more information to track down the problem.

Good luck :)
That empty string is simply indication that $data is empty. Check to make sure $data contains a value before running the query.

And in the future, enclose code blocks in the [nobbc][code][/code][/nobbc] tags. It makes your code much easier to read.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.