MySQL Database call help
07-07-2010, 11:17 PM, (This post was last modified: 07-07-2010, 11:33 PM by RichardGv.)
#2
RE: MySQL Database call help
The SQL query you used shouldn't work correctly since "SELECT * FROM users WHERE gender='$gender'" finds users whose gender is the value of $gender. But $gender is undefined at the time. You are supposed to use "SELECT gender FROM users WHERE username='$username'" or something like that, I think. (Do not tell me this SQL query is bust again! The SQL query very possibly won't work without modifications because I have no idea about the columns and structure of your SQL table. $username needs to be replaced with the correct username variable, as well. $_SESSION['username']? That does not seem nice enough.)
The reason that var_dump() returns false is the SQL query is incorrect and there's no rows returned from the query. mysql-fetch-array() returns FALSE if there are no rows.

Even if the SQL query is corrected, your code still won't work correctly. It will print out "Array" instead of the correct gender. mysql-fetch-array() returns an array, so $gender should be an array instead of a string variable. You cannot display an array with echo correctly.

Also, I think relearning SQL would be a nice idea for you.
Gentoo Linux User (w/ fvwm) / Loyal Firefox User / Owner of a Stupid Old Computer - My PGP Public Key

No man is an island, entire of itself; every man is a piece of the continent, a part of the main; if a clod be washed away by the sea, Europe is the less, as well as if a promontory were, as well as if a manor of thy friends or of thine own were; any man's death diminishes me, because I am involved in mankind; and therefore never send to know for whom the bell tolls; it tolls for thee.
-- Devotions Upon Emergent Occasions (1624), John Donn
Reply


Messages In This Thread
MySQL Database call help - by Cameron - 07-07-2010, 03:52 PM
RE: MySQL Database call help - by RichardGv - 07-07-2010, 11:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  MySql backup? Mone 1 1,270 06-01-2011, 02:29 AM
Last Post: capp

Forum Jump: