BigX Posted February 11, 2008 Share Posted February 11, 2008 Hi guys, I'm kinda new to PHP! Working on a site now but I'm getting the next parse/syntax error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in [path removed] on line 95 The code I have is: <?php $query = "SELECT id_usr FROM ekpoule_users WHERE level_usr = User ORDER BY id_usr ASC"; $berekenen = mysql_query($query); while($row = mysql_fetch_array($berekenen, MYSQL_ASSOC)) { // Zwitserland - Tsjechie (uitslag) $query = mysql_query("SELECT uitslag FROM echte_uitslagen WHERE wedstrijd = 'zwitserland_tsjechie'"); $echte_uitslagen = mysql_fetch_array($query); $query = mysql_query("SELECT ZWI_TSJ_uitslag FROM `poule a` WHERE user_id = $row['id_usr']"); $poule_a = mysql_fetch_array($query); if( $poule_a['ZWI_TSJ_uitslag'] == $echte_uitslagen['uitslag'] ) { mysql_query("UPDATE puntentelling SET zwitserland_tsjechie_uitslag = '15' WHERE id = $row['id_usr']"); } else { mysql_query("UPDATE puntentelling SET zwitserland_tsjechie_uitslag = '0' WHERE id = $row['id_usr']"); } } ?> line 95 is this one: $query = mysql_query("SELECT ZWI_TSJ_uitslag FROM `poule a` WHERE user_id = $row['id_usr']"); Hopefully some of you guys know the error! I suspect it has someone to do with the user_id = $row['id_usr']"); I have tried '$row['id_usr']' "); but that didn't do the trick! thanks in advance edit by thorpe: Please use tags to enable syntax highlighting. Quote Link to comment Share on other sites More sharing options...
AndyB Posted February 11, 2008 Share Posted February 11, 2008 I suspect that the problem is caused by naming a table `poule a`. The parser can't make sense of the space. Better to rename that table without spaces, e.g. poule_a Quote Link to comment Share on other sites More sharing options...
BigX Posted February 11, 2008 Author Share Posted February 11, 2008 I suspect that the problem is caused by naming a table `poule a`. The parser can't make sense of the space. Better to rename that table without spaces, e.g. poule_a Yeah I feel you on that one! I figured this out also but I have used `poule a` a whole lot on the site before figuring that out but the strange thing is that when using `poule a` it never gave any problems before (using only poule a did but the ` ` solved the problem)! All my next poules I called poule_b, poule_c etc but I don't think `poule a` is the problem since this code for example is working fine and it also uses `poule a`: <?php $query = mysql_query("SELECT uitslag FROM echte_uitslagen WHERE wedstrijd = 'zwitserland_tsjechie'"); $echte_uitslagen = mysql_fetch_array($query); $query = mysql_query("SELECT ZWI_TSJ_uitslag FROM `poule a` WHERE user_id = '{$_SESSION['kt_login_id']}'"); $poule_a = mysql_fetch_array($query); if( $poule_a['ZWI_TSJ_uitslag'] == $echte_uitslagen['uitslag'] ) { mysql_query("UPDATE puntentelling SET zwitserland_tsjechie_uitslag = '15' WHERE id = '{$_SESSION['kt_login_id']}'"); echo "15"; } else { mysql_query("UPDATE puntentelling SET zwitserland_tsjechie_uitslag = '0' WHERE id = '{$_SESSION['kt_login_id']}'"); echo "0"; } ?> Quote Link to comment Share on other sites More sharing options...
BigX Posted February 11, 2008 Author Share Posted February 11, 2008 Also when I try in my_sql: SELECT ZWI_TSJ_uitslag FROM `poule a` WHERE user_id = 4 it works and it gives the results so I really think the problem lies in user_id = $row['id_usr']"); Anyone any other suggestions?? Greetz Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 11, 2008 Share Posted February 11, 2008 do this user_id='$row[id_usr]'"); Quote Link to comment Share on other sites More sharing options...
nethnet Posted February 11, 2008 Share Posted February 11, 2008 Try this: <?php $sql = "SELECT ZWI_TSJ_uitslag FROM `poule a` WHERE user_id = \"{$row['id_usr']}\""; $query = mysql_query($sql) or die("Error in the query: " . mysql_error()); ?> If that does not work, try echoing $sql to ensure that the query is exactly what it should be. Quote Link to comment Share on other sites More sharing options...
BigX Posted February 11, 2008 Author Share Posted February 11, 2008 do this user_id='$row[id_usr]'"); Thanks this seemed to work! I replaced it and the syntax error was gone! The problem now is that I get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [path removed] on line 95 This is the code now around line 95: $query = "SELECT id_usr FROM ekpoule_users WHERE level_usr = User ORDER BY id_usr ASC"; $berekenen = mysql_query($query); while($row = mysql_fetch_array($berekenen, MYSQL_ASSOC)) { When inserting the above in My_sql I get: #1054 - Unknown column 'User' in 'where clause' In the WHERE part I have a column level_usr where there could be filled in 'Admin' or 'User' and I only want to select the Users form this column! Should I place User between ' ' or something?? Normally this worked for me... Thanks in advance for putting time into this Greetz Quote Link to comment Share on other sites More sharing options...
nethnet Posted February 11, 2008 Share Posted February 11, 2008 It should be level_usr = 'User'. Don't forget quotes. Quote Link to comment Share on other sites More sharing options...
BigX Posted February 11, 2008 Author Share Posted February 11, 2008 It should be level_usr = 'User'. Don't forget quotes. Thanks when I tried level_usr = 'User' I did get a result when putting this into my_sql (2, 3, 4, 5 etc) but I still get the: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [path removed] on line 95 Line 95 is the While loop: while($row = mysql_fetch_array($berekenen, MYSQL_ASSOC)) { I don't know what's wrong here! I know there are valid my_sql results but it still has a problem somewhere! Whole code: <?php $query = "SELECT id_usr FROM ekpoule_users WHERE level_usr = 'User' ORDER BY id_usr ASC"; $berekenen = mysql_query($query); while($row = mysql_fetch_array($berekenen, MYSQL_ASSOC)) { // Zwitserland - Tsjechie (uitslag) $query = mysql_query("SELECT uitslag FROM echte_uitslagen WHERE wedstrijd = 'zwitserland_tsjechie'"); $echte_uitslagen = mysql_fetch_array($query); $query = mysql_query("SELECT ZWI_TSJ_uitslag FROM `poule a` WHERE user_id = '$row[id_usr]'"); $poule_a = mysql_fetch_array($query); if( $poule_a['ZWI_TSJ_uitslag'] == $echte_uitslagen['uitslag'] ) { mysql_query("UPDATE puntentelling SET zwitserland_tsjechie_uitslag = '15' WHERE id = '$row[id_usr]'"); } else { mysql_query("UPDATE puntentelling SET zwitserland_tsjechie_uitslag = '0' WHERE id = '$row[id_usr]'"); } } ?> Quote Link to comment Share on other sites More sharing options...
nethnet Posted February 11, 2008 Share Posted February 11, 2008 That warning is telling you that $berekenen is not of type RESOURCE like it should be in order to be used in the mysql_fetch_array() function. Most likely, it is of type BOOLEAN, more specifically FALSE because the query failed. Add this for debugging purposes and see if a mysql error is returned: <?php $berekenen = mysql_query($query) or die("Query error: " . mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
BigX Posted February 11, 2008 Author Share Posted February 11, 2008 That warning is telling you that $berekenen is not of type RESOURCE like it should be in order to be used in the mysql_fetch_array() function. Most likely, it is of type BOOLEAN, more specifically FALSE because the query failed. Add this for debugging purposes and see if a mysql error is returned: <?php $berekenen = mysql_query($query) or die("Query error: " . mysql_error()); ?> When I added what you told me I got: Query error: No database selected I kinda understand what you were saying about the RESOURCE not being valid but is there a way to change that?? Maybe I should explain a bit more what I'm trying to accomplish in the first place! I'm making a poule for the upcoming European Championships Soccer (we love that in Europe )! I have a table with all the people that join the poule and everyone has a unique id (id_usr) using the $row I need to select this unique id to run a script for all the users to give them points (or not) for a specific match result! So the script need to select id=2 (id=1 is the Admin) and give that person points for the matches (all the matches are between the { } of the While loop)/ After this id=3, id=4 etc! A person really good at PHP told me this was the way to go, but he's away for 6 weeks starting yesterday so I can't ask him for help! Is this While loop idea the right thing to use?? Quote Link to comment Share on other sites More sharing options...
nethnet Posted February 11, 2008 Share Posted February 11, 2008 It is saying you haven't selected a database. You need these two lines of code to initiate a database session: <?php $link = mysql_connect("server","username","password"); mysql_select_db("database",$link); ?> It's best to put that in a file called db.php and include it on every page. You'll have to change all the values in quotes to your actual values. Quote Link to comment Share on other sites More sharing options...
BigX Posted February 11, 2008 Author Share Posted February 11, 2008 It is saying you haven't selected a database. You need these two lines of code to initiate a database session: <?php $link = mysql_connect("server","username","password"); mysql_select_db("database",$link); ?> It's best to put that in a file called db.php and include it on every page. You'll have to change all the values in quotes to your actual values. Well on top of my page I have: <?php require_once('Connections/ekpoule08.php'); ?> <?php //initialize the session if (!isset($_SESSION)) { session_start(); } ?> And in ekpoule08.php it says: <?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_ekpoule08 = "#####"; $database_ekpoule08 = "#######"; $username_ekpoule08 = "######"; $password_ekpoule08 = "########"; $ekpoule08 = mysql_pconnect($hostname_ekpoule08, $username_ekpoule08, $password_ekpoule08) or trigger_error(mysql_error(),E_USER_ERROR); ?> Is this what you mean?? I have the same thing on all the other pages of the site and the connection with the database works fine there: joost.dvdcollectie.com/ekpoule2008 on the first page index there is allready connection being made with the database... Quote Link to comment Share on other sites More sharing options...
nethnet Posted February 11, 2008 Share Posted February 11, 2008 Okay but you are still NOT selecting a database. You have opened a connection to the MySQL server, but until you select a database, your script is not going to work. Back to what I said before, use the function mysql_select_db() to select the database. Quote Link to comment Share on other sites More sharing options...
BigX Posted February 11, 2008 Author Share Posted February 11, 2008 Ahhh it finally did work Thanks very much!!!!!!! You're a life saver! Well maybe that's a bit too but I really appreciate you putting your time into helping me out here! THANX Quote Link to comment Share on other sites More sharing options...
nethnet Posted February 11, 2008 Share Posted February 11, 2008 No problem, good luck with the rest of your project. Regards, Theo 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.