Kip Gordon wrote:
I connect to my data base...
$dbh=mysql_connect ("localhost", "kipples_women", "xxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("kipples_hotwomen");
and then I issue a query..
$query="SELECT * FROM women WHERE index = $id"; $result=mysql_query($query) or die("Query failed : " . mysql_error());
now here's where it gets funky, and where I can't figure out what is going wrong... I now have it display the information from the row that has the field "index" and where index is equal to $id (the number from the url). Now, say that $id was equal to 21... I get an error message that says.." Query failed : You have an error in your SQL syntax. Check the manualthat corresponds to your MySQL server version for the right syntax to use near 'index = 21' at line 3" Now, first of all, it isnt on line3, its like line 128 or something...
The error message is coming from mysql with regard to your 3-line query. The mysql server has no way of knowing which line of your script sent the query.
The problem is that index is a reserved word. Your best bet would be to use a different name for the column, id perhaps. If you wish to use a column named index, you must enclose it in backticks, like this:
$query="SELECT * FROM women WHERE `index` = $id";
But I'd recommend
ALTER TABLE women CHANGE `index` id INT;
to rename the index column to id. (Replace "INT" with the same column type you used to define index.) Then your query becomes
$query="SELECT * FROM women WHERE id = $id";
No more need for backticks, and "WHERE id = $id" is intuitive.
second.. I can't see anything wrong with that syntax... My SQL server version is 4.0.18-standard and I can't find documentation for it. I also
See the online manual <http://dev.mysql.com/doc/mysql/en/>.
tried to use LIMIT $id Oo and it gets even weirder. I can get a result with LIMIT $id.... but it pulls the wrong row! if $id equals 24 for example, it will get the row with a value of 7 in the field for index.... I don't get it.. Even had a friend look at it and he said it all looked good..
I'm not sure what you mean by "LIMIT $id Oo", but no, it doesn't pull the wrong row. LIMIT has nothing to do with which rows are selected. That's the job of the WHERE clause. Nor does it have anything to do with how the returned rows are sorted. That's the job of the ORDER BY clause. LIMIT is used to determine how many rows are returned if you don't want them all. Thus, LIMIT 24 means you want the first 24 rows that match your WHERE clause. See the manual <http://dev.mysql.com/doc/mysql/en/SELECT.html> for the complete SELECT syntax.
I'd really appreciate any help anyone could throw at me... I'm rather new to all this!
Thanks, Kip Gordon
We were all new once. Hope this helps.
Michael
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]