jeger003 Posted February 22, 2009 Share Posted February 22, 2009 hello everyone, im trying to call a value from the database so i can use in an if() statement but i dont want to use while() is there another way to do it? here is what i have but of course it dont work $user_id_cookie = $_COOKIE['user_id']; $query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id"); //$fetch_email = mysql_fetch_array($query_private) if(!empty($query_private)) { $this->body .= "<input type=text name=b[email] value=\"".$query_private['private_email']."\" class=details>"; } else { $this->body .= "<input type=text name=b[email] value=\"".$current_email."\" class=details>"; } Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 you have to use mysql_fetch_array on $query_private to get an array from result. Quote Link to comment Share on other sites More sharing options...
jeger003 Posted February 22, 2009 Author Share Posted February 22, 2009 you have to use mysql_fetch_array on $query_private to get an array from result. i tried that but i keep getting error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result on line 173 " line 173 is $fetch_email = mysql_fetch_array($query_private); $user_id_cookie = $_COOKIE['user_id']; $query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id_cookie"); $fetch_email = mysql_fetch_array($query_private); if(!empty($fetch_email['private_email'])) { $this->body .= "<input type=text name=b[email] value=\"".$fetch_email['private_email']."\" class=details>"; } else { $this->body .= "<input type=text name=b[email] value=\"".$current_email."\" class=details>"; } Quote Link to comment Share on other sites More sharing options...
dmccabe Posted February 22, 2009 Share Posted February 22, 2009 Try $fetch_email = mysql_query($query_private); $row = mysql_fetch_row($fetch_email); and if(!empty($row[0])) { $this->body .= "<input type=text name=b[email] value=\"".$row[0]."\" class=details>"; Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 i tried that but i keep getting error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result on line 173 " line 173 is $fetch_email = mysql_fetch_array($query_private); This indicates, that the query failed. Try to display mysql_error Quote Link to comment Share on other sites More sharing options...
jeger003 Posted February 22, 2009 Author Share Posted February 22, 2009 i tried that but i keep getting error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result on line 173 " line 173 is $fetch_email = mysql_fetch_array($query_private); This indicates, that the query failed. Try to display mysql_error your right.........now the error is You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 @dmccabe i tried your code and it gave me same error as above........i dont understand whats going on Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Change $query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id_cookie"); to $sql = "SELECT private_email FROM user WHERE id = $user_id_cookie"; $query_private = mysql_query($sql) or die(mysql_error().": $sql"); Quote Link to comment Share on other sites More sharing options...
jeger003 Posted February 22, 2009 Author Share Posted February 22, 2009 Change $query_private = mysql_query("SELECT private_email FROM user WHERE id = $user_id_cookie"); to $sql = "SELECT private_email FROM user WHERE id = $user_id_cookie"; $query_private = mysql_query($sql) or die(mysql_error().": $sql"); new error says You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1: SELECT private_email FROM user WHERE id = Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Well here you are: $user_id_cookie is empty. Quote Link to comment Share on other sites More sharing options...
jeger003 Posted February 22, 2009 Author Share Posted February 22, 2009 Well here you are: $user_id_cookie is empty. omg your right.......i was calling user id in cookie.....my cookies dont store user ids.......man i would have been at it all day had you not have caught this... thanks so much... in the future how can i use your technique?? i can just enter $query_private = mysql_query($sql) or die(mysql_error().": $sql"); $sql can be the query to check? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Yup, that's how it's done. Quote Link to comment Share on other sites More sharing options...
jeger003 Posted February 22, 2009 Author Share Posted February 22, 2009 thanks so much!!! Quote Link to comment 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.