|
|
|
|
![]() ![]() |
Aug 4 2006, 03:23 AM
Post
#11
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
$sql = "SELECT * FROM `users`, `content` WHERE `access_name`='$active_user' AND `users.id`= 'content.id'"; How does users.id and content.id work anyway. You are most likely getting the error on trying to fetch the array because the syntax is wrong or something you try to grab does not exist (meaning it could still mean wrong syntax). Didn't work.... I don't even know how it works... I'm going off the pointless examples that don't make any sense... I've been googling & looking through my PHP & MySQL books... so based on these confusing examples, I revised my code to this: CODE $sql = "SELECT * " . "FROM users u " . "JOIN content c " . "WHERE access_name='$active_user' AND id = 'id'"; $row = mysql_fetch_array(mysql_query($sql)); and for some reason, it's complaining about this line: $row = mysql_fetch_array(mysql_query($sql)); It's always that line whenever I work with MySQL... that's why I hate working with it so much... [N]F |
|
|
|
Aug 4 2006, 03:34 AM
Post
#12
|
|
|
Teh Coder Group: Members Posts: 1,053 Joined: 18-April 06 From: Australia Member No.: 12,833 |
Yeah because of the mysql_fetch_array, it errors because the syntax is incorrect for the SQL or your'e not asking for information exists.
|
|
|
|
Aug 4 2006, 12:33 PM
Post
#13
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
ok,ok... I took an example from my other php book and now, I replaced
$row = mysql_fetch_array(mysql_query($sql)); to $result = mysql_query($sql) or die(mysql_error()); and now, I got a different error message: Column 'id' in where clause is ambiguous At least it is better than working with Microsoft errors which tell you nothing... I can partly understand what that means... Edit: Ok, I re-did the code and it's now this: CODE $sql = "SELECT * " . "FROM users u " . "JOIN content c " . "WHERE u.access_name='$active_user' AND u.id = 'c.cid'"; $row = mysql_fetch_array(mysql_query($sql)); not producing any errors, but now I see my "Invalid ID or General Error" message even when I try to execute the script with a VALID access name (test.php?id=access_name) [N]F This post has been edited by nightfox: Aug 4 2006, 12:46 PM |
|
|
|
Aug 4 2006, 05:45 PM
Post
#14
|
|
|
Guilty Until Proven Innocent Group: Members Posts: 372 Joined: 13-April 05 Member No.: 3,937 |
Edit: Ok, I re-did the code and it's now this: CODE $sql = "SELECT * " . "FROM users u " . "JOIN content c " . "WHERE u.access_name='$active_user' AND u.id = 'c.cid'"; $row = mysql_fetch_array(mysql_query($sql)); not producing any errors, but now I see my "Invalid ID or General Error" message even when I try to execute the script with a VALID access name (test.php?id=access_name) [N]F Please recode that to this one.. you have problems with the quotes.. use ` when you want to say table name or column name. avoid using ' since mySQL dont understand that well.. " is use for table names.. CODE $sql = "SELECT * " . "FROM users u " . "JOIN content c " . "WHERE `u`.`access_name` = `" . $active_user. "` AND `u`.`id` = `c`.`cid`"; $row = mysql_fetch_array(mysql_query($sql)); I hope this solves the problem. *********** about the $active_user where do you get its value? it seems that you are using this variable but it was never been given a value. please use this for visual test after the declaration of $sql CODE echo $sql; if the "name =" part have nothing in its rigth side then, you gave fail to assign $active_user a value. This post has been edited by vhortex: Aug 4 2006, 05:49 PM |
|
|
|
Aug 4 2006, 07:21 PM
Post
#15
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
CODE $sql = "SELECT * " . "FROM users u " . "JOIN content c " . "WHERE `u`.`access_name` = `" . $active_user. "` AND `u`.`id` = `c`.`cid`"; $row = mysql_fetch_array(mysql_query($sql)); I hope this solves the problem. *********** Nope, didn't work... it's still complaining about $row ... Visual reference of the $sql: SELECT * FROM users u JOIN content c WHERE `u`.`access_name` = `silly_george` AND `u`.`id` = `c`.`cid` QUOTE about the $active_user where do you get its value? it seems that you are using this variable but it was never been given a value. It has a value... well, it's from the URL... my original code: CODE // ############################################# $active_user = $_GET['id']; // ############################################# so basically, if there's a valid access name that comes after the ?id= in the URL, then fetch that user's content for their profile out of the content table. [N]F |
|
|
|
Aug 4 2006, 09:03 PM
Post
#16
|
|
|
Guilty Until Proven Innocent Group: Members Posts: 372 Joined: 13-April 05 Member No.: 3,937 |
please try this one instead..
CODE SELECT * FROM users u JOIN content c WHERE `u`.`access_name` = \"" . $active_user. "\" AND `u`.`id` = `c`.`id` the changes are in the quotes.. \"" . $active_user. "\" plus this typo `c`.`id` i hope this will work now |
|
|
|
Aug 4 2006, 11:08 PM
Post
#17
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
grrr...
now it is giving me Parse error: parse error, unexpected T_VARIABLE for line 18... guess which line that is as for the code, I'm assuming it is supposed to be like this: CODE $sql = "SELECT * FROM users u JOIN content c WHERE `u`.`access_name` = \"" . $active_user. "\" AND `u`.`id` = `c`.`id`" I think that section just needs to be tweaked and then it should work... this script is really starting to get annoying and I'm tempted to put it all into one table... UPDATE: I GOT IT TO WORK!!! Well, I cheated... I took the semi-long-and-not-nearly-effective way to do it... here's what I did: CODE $sql = "SELECT * FROM users WHERE `access_name` = \"" .$active_user. "\""; $row = mysql_fetch_array(mysql_query($sql)); $user_id = $row['id']; $sql2 = "SELECT * FROM content WHERE `cid` = \"" .$user_id. "\""; $row2 = mysql_fetch_array(mysql_query($sql2)); As you can see, since I called up one query which has the User ID number in it and then turned that number into a variable to link the two databases... [N]F This post has been edited by nightfox: Aug 4 2006, 11:55 PM |
|
|
|
Aug 5 2006, 01:40 AM
Post
#18
|
|
|
Teh Coder Group: Members Posts: 1,053 Joined: 18-April 06 From: Australia Member No.: 12,833 |
Also have you considered using $_REQUEST? Instead of $_POST or $_GET, I'm pretty sure it handles both and I have been using it for some time without fail
|
|
|
|
Aug 5 2006, 03:27 AM
Post
#19
|
|
|
the Q Group: [HOSTED] Posts: 1,054 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 |
Also have you considered using $_REQUEST? Instead of $_POST or $_GET, I'm pretty sure it handles both and I have been using it for some time without fail I personally avoid to use $_REQUEST; superglobal, but I know quite a lot of people who like to use it, so I guess it is alright, but it can make problems in your script, because I never trust user coming information into my script, so knowing through which method it came is quite alright, especially if you use both methods, but for some time now I really like to use QUERY_STRING with which you get the string index.php?string and even better PATH_INFO, with which you can get the string which comes from /index.php/string, but eventually I don't have anything against $_REQUEST; I just avoid it |
|
|
|
Aug 5 2006, 04:47 AM
Post
#20
|
|
|
Guilty Until Proven Innocent Group: Members Posts: 372 Joined: 13-April 05 Member No.: 3,937 |
QUOTE as for the code, I'm assuming it is supposed to be like this: CODE $sql = "SELECT * FROM users u JOIN content c WHERE `u`.`access_name` = \"" . $active_user. "\" AND `u`.`id` = `c`.`id`" yeah, you are rigth.. i just posted the query.. i was so sleepy when i do that and lazy tooo... CODE $sql = "SELECT * FROM users u JOIN content c WHERE `u`.`access_name` = \"" . $active_user. "\" AND `u`.`id` = `c`.`id`"; there is a semicolon at the end.. and the parse error is that it is suppose to inside a quote string variable.. -------- They told me this when I started.. Good programmers -- modular / Object oriented approach of programming.. Good programmers -- reuses well crafted codes as libraries.. Good programmers -- have less work to do.. Good programmers -- turns into lazy people.. I guess i put much more focus on the lazt stuff. maybe if i was lazy enough i can be a good programmer.. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 15th October 2008 - 07:09 PM |