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>"; } Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/ 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. Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768488 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>"; } Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768522 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>"; Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768528 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 Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768538 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 Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768541 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"); Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768545 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 = Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768552 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. Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768554 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? Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768567 Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Yup, that's how it's done. Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768571 Share on other sites More sharing options...
jeger003 Posted February 22, 2009 Author Share Posted February 22, 2009 thanks so much!!! Link to comment https://forums.phpfreaks.com/topic/146368-solved-how-do-i-call-specifc-values-with-out-using-while/#findComment-768574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.