| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Mar 2006 Location: USA
Posts: 497
![]() ![]() | More PHP Help Alright I have a script that needs to retrieve data from inside a mysql column. It need to be a speific column. Here is the database: Database---users(table)---*username*(the column)----health(data needed) **= i am using a login script and each person needs to sign up and a column thing is created in the users table (username, password, health, etc.) How do i retrive the data in health from a certain user that is logged in? <? echo $_COOKIE['user']; ?> that line echos the username of the logged in person on to the webpage. |
| |
| | #2 (permalink) |
| Tech Support Join Date: Mar 2005
Posts: 4,944
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code: |
| |
| | THREAD STARTER #3 (permalink) |
| NamePros Regular Join Date: Mar 2006 Location: USA
Posts: 497
![]() ![]() | Thank you sooo! much! i get this: welcome qwerty error #103You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1The query was Resource id #5 ok i know whats wrong: i have this: PHP Code:
Last edited by snike; 05-02-2006 at 05:01 PM.
|
| |
| | #4 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,792
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You can't echo $query. After SecondVersion's script (still inside the PHP tags) add: $health = mysql_fetch_row($query); echo $health; edit: I see your edit.. You need to echo $row[0] and not $query (print.. echo.. w/e) mysql_fetch_assoc is slower than mysql_fetch_row and other ones. |
| |
| | THREAD STARTER #5 (permalink) |
| NamePros Regular Join Date: Mar 2006 Location: USA
Posts: 497
![]() ![]() | Is this okay? cuz it still dont work <? include("check.php"); ?> <? include("db.php"); ?> <html> <head> <title></title> </head> ????: NamePros.com http://www.namepros.com/showthread.php?t=193411 <body bgcolor="#FFFFFF"> welcome <? echo $_COOKIE['user']; ?> <? ## Retrive Health Start //Define query $user = $_COOKIE['user']; $query = mysql_query("SELECT health FROM users WHERE username = '".$user."'") or die("Error getting user info:<br />".mysql_error()); if($r = mysql_query($query)) { //Retrive and print while ($row = mysql_fetch_array($r)) { echo "$row[0]\n"; } } else { die('<b>Kingdom Tempost Error #103</b> '.mysql_error().'The query was '.$query); } mysql_close(); ?> </body> </html>
Last edited by snike; 05-02-2006 at 05:11 PM.
|
| |
| | #6 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,792
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code: |
| |
| | #11 (permalink) |
| Tech Support Join Date: Mar 2005
Posts: 4,944
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code: |
| |