backslash Posted June 12, 2008 Share Posted June 12, 2008 <?php $posts = mysql_num_rows(mysql_query("SELECT * FROM phpbb_posts", $con_posts)) $users = mysql_num_rows(mysql_query("SELECT * FROM phpbb_users", $con_users))-52 ?> Parse error: syntax error, unexpected T_VARIABLE in __ on line 1 All the database calls are in another <?php ?> block, they worked fine until I had them call the password from another text file for security reasons. Is there any complaint you could see in these lines? Also, the two methods I tried for calling the password from the other file was to simply read it line for line and then assign it to variables, but I changed it (neither way worked) so that the variables are declared in the other file. Any ideas? Oh and heres the code for the other page (all the __'s are intentional ommisions, no single or double quotes were omitted) <?php require(__); $con_posts = mysql_connect("$ip","$un","$pw"); // these variables are from the required file $con_users = mysql_connect("$ip","$un","$pw"); if (!$con_posts) { die('con_posts died: ' . mysql_error()); } if (!$con_users) { die('con_users died: ' . mysql_error()); } mysql_select_db("__", $con_posts); mysql_select_db("__", $con_users); ?> Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/ Share on other sites More sharing options...
BlueSkyIS Posted June 12, 2008 Share Posted June 12, 2008 missing semi-colon at the end of each line. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564266 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 Actually, moving those to their own line (and forgetting the semicolons) was something I did AFTER the error arose, and the error followed the query. Furthermore, it says error on line 1, semicolon errors almost always are not determined until line 2. I added them, thought you were right, and I was psyched about it, but I still get: Parse error: syntax error, unexpected T_VARIABLE in __ on line 1 Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564455 Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 ummm... which is line 1? ca you post the modified code you have? Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564457 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 <?php require(__); $con_posts = mysql_connect("$ip","$un","$pw"); $con_users = mysql_connect("$ip","$un","$pw"); mysql_select_db("__", $con_posts); mysql_select_db("__", $con_users); ?> <?php $posts = mysql_num_rows(mysql_query("SELECT * FROM phpbb_posts", $con_posts)); $users = mysql_num_rows(mysql_query("SELECT * FROM phpbb_users", $con_users))-52; echo "Posts: <b>". $posts ."</b><br>"; echo "Users: <b>". $users ."</b>"; ?> <br> Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564459 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 Why are you creating two separate database connections? Bad idea, unless you need to. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564462 Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 Why are you creating two separate database connections? Bad idea, unless you need to. moreover, is that really line 1? are thsoe all the lines you have? does that line 1 is pointing to the required php script? am not getting the problem, or maybe i overlooked it myself Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564467 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 The problem is ACTUALLY in the second <?php ?> chunk. If I comment out $posts = mysql_num_rows(mysql_query("SELECT * FROM phpbb_posts", $con_posts)); $users = mysql_num_rows(mysql_query("SELECT * FROM phpbb_users", $con_users))-52; they go away. Also, why shouldn't I create two connections? I could just use the same connection twice I guess. Actually I'm not sure why I didn't.. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564477 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 PHP is on crack! I moved the <div> that contained this broken code down below another piece of the code, and the whole page turned to an error, and then I switched it back because thats much worse, and now, the main page is STILL broken after I reverted to the old file. I am so confused. Is it possible that a bad FTP program is causing some horrid corruption? Because I have only tried 2 or 3 files, but everything I've uploaded from filezilla returns this error. I don't want to test it further/ Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564481 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 It has nothing to do with your FTP program, it has to do with you coding this poorly, no offense. =/ Post some more code and I'll help you sort it out. And try to describe the problem as best as you can, and the purpose of the code. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564486 Share on other sites More sharing options...
kenrbnsn Posted June 13, 2008 Share Posted June 13, 2008 What editor are you using to create you scripts? It's possible that the editor is inserting hidden characters in your file. Ken Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564487 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 What editor are you using to create you scripts? It's possible that the editor is inserting hidden characters in your file. Ken That could cause header issues (someone had that issue and I spent like, 30 minutes and 6 PMs trying to explain to them what to do, lol), but I don't think it would really cause a MySQL issue like that. But alas, he should check out the editor to eliminate any potential problems later on. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564489 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 Well I used notepad2 all along, then I used it on Vista for a bit, then XP again. But still notepad2. Any other suggested editor? Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564491 Share on other sites More sharing options...
kenrbnsn Posted June 13, 2008 Share Posted June 13, 2008 Make sure you're saving the file as plain ASCII and you don't have your character-set set to UTF-8. If UTF-8 is set the editor will put some strange characters in front of your text and PHP will barf. Ken Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564492 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 Notepad++ or Eclipse are good as well. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564494 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 Alright, well now that I found it was Notepad2 on Vista that was screwing things around, I have gotten to a point where all I have to do is fix the files. I have a small error, but its an actual code error, so I think I should be able to handle it from here. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564495 Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 Notepad++ or Eclipse are good as well. yep... those two are nice. but if you want to have a lightweight yet better than notepad++, you may use phpdesigner2007 personal. there was 2008 version but 2007 would do. how bout dissecting your code instead of nesting: $posts = mysql_num_rows(mysql_query("SELECT * FROM phpbb_posts", $con_posts)); $users = mysql_num_rows(mysql_query("SELECT * FROM phpbb_users", $con_users))-52; to: $posts_resource = mysql_query("SELECT * FROM phpbb_posts", $con_posts); $users_resource = mysql_query("SELECT * FROM phpbb_users", $con_users); $posts = mysql_num_rows($posts_resource); $users = mysql_num_rows($users_resource); $users_deducted = $users - 52; its a lot cleaner and you can see more clearly where the error really occured. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564496 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 Heres how everything sits now. Sadly I dont understand the error. I learned PHP and SQL two nights ago, and only learn as I go, so there is very likely a shining error. I am thinking that my attempt to connect a funny way failed? However, I can print the variables in that file no problem. 9 mysql_select_db("darktalon_forum", $con_posts); 10 $posts_resource = mysql_query("SELECT * FROM phpbb_posts", $con_posts); 11 mysql_select_db("darktalon_forum", $con_users); 12 $users_resource = mysql_query("SELECT * FROM phpbb_users", $con_users); 13 14 $posts = mysql_num_rows($posts_resource); 15 $users = mysql_num_rows($users_resource) - 52; Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in __/html/sidebar on line 9 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in __/html/sidebar on line 10 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in __/html/sidebar on line 11 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in __/html/sidebar on line 12 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in __/html/sidebar on line 14 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in __/html/sidebar on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564502 Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 the connection really is busted. can you post your code when you connect until that line? its hard to check for errors if you don't the previous codes which might have led to it. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564505 Share on other sites More sharing options...
backslash Posted June 13, 2008 Author Share Posted June 13, 2008 1 <?php 2 require(fubar_forum); 3 $con_forum = mysql_connect("$ip","$un","$pw"); 4 if(!$con_forum) 5 { 6 die('Cannot connect' . mysql_error()); 7 } I changed the name of the connection, then didnt move the change to the other parts. OMG I am so sorry guys, every problem I have asked help for is my own stupidity. This is why I hesitated to join this forum when I had my first batch of problems. I've become the type of coder I hate. Dependent. THANK YOU ALL YOUR AMAZING HELP, Without the suggestion about my text editor, I would have probably just dug the site deeper and deeper into oblivion and hated PHP forever. And sorry for asking help for things I should have done on my own. Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564510 Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 do you mean to say that you managed to solve it now? feel free to ask... am just new to this forum also, around 3 days? am also newbie in PHP, less than a year. anyway askin is fine. but its always better to do things on our own first, do some effort on crawling the web and some research before asking. lets just help each other... cheers, Jay Quote Link to comment https://forums.phpfreaks.com/topic/109954-annoying-problem/#findComment-564520 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.