digitalbill Posted January 24, 2007 Share Posted January 24, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/35541-select-syntax-incorrect-for-where/ Share on other sites More sharing options...
btherl Posted January 29, 2007 Share Posted January 29, 2007 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/35541-select-syntax-incorrect-for-where/#findComment-171668 Share on other sites More sharing options...
neylitalo Posted January 31, 2007 Share Posted January 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/35541-select-syntax-incorrect-for-where/#findComment-173517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.