Centurian Posted January 30, 2011 Share Posted January 30, 2011 Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or T_NUM_STRING... I'm getting this error for this line: if ((int)$row['loyalty']<20) Thanks in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/ Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2011 Share Posted January 30, 2011 The error is probably before that line. Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167325 Share on other sites More sharing options...
Centurian Posted January 30, 2011 Author Share Posted January 30, 2011 echo "No result <BR>"; echo "SELECT * FROM ".$user."Crew"; } while($row = mysql_fetch_array($result)) { if ((int)$row['loyalty']<20) Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167326 Share on other sites More sharing options...
PaulRyan Posted January 30, 2011 Share Posted January 30, 2011 Post all of you code, just a few lines here and there will not help us to help you. Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167331 Share on other sites More sharing options...
Centurian Posted January 30, 2011 Author Share Posted January 30, 2011 Sure, but its a pretty massive file. I'll post a good chunk of it. Its part of a function I use in a game I'm making. Basically, it generates a description of a particular unit. It works by connecting to my MySQL database, grabbing the matching data, then using a bunch of if statements to find problems with it. function getcomment($user,$id) { $con = mysql_connect("localhost","admin","******"); if (!$con) { echo "Could not connect."; } $lols = mysql_select_db("********", $con); if (!$lols) { echo "Could not select database."; } $result = mysql_query("SELECT * FROM ".$user."Crew WHERE id = $id "); if (!$result) { echo "No result <BR>"; } while($row = mysql_fetch_array($result)) { if ((int)$row['loyalty']<20) { if ($row['rank']="XO") { return "$row['Name']." is openly mutinous towards you - s/he is not suitable as an XO."; goto endsub; } else { return "$row['Name']." is unhappy with your leadership."; goto endsub; } endsub: } mysql_close($con); } Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167333 Share on other sites More sharing options...
Zurev Posted January 30, 2011 Share Posted January 30, 2011 Assuming it'll work if you switch it to that, also added an equals sign since you were setting the variable = XO everytime, you need to work on learning how variables work in double/single quotes and when concatenation is required. if ($row['rank']=="XO") { return $row['Name']." is openly mutinous towards you - s/he is not suitable as an XO."; goto endsub; } else { return $row['Name']." is unhappy with your leadership."; goto endsub; } More on your variables in strings.... ("SELECT * FROM ".$user."Crew WHERE id = $id ") That's a prime example right there - why did you leave the quotes on one but not the other? Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167339 Share on other sites More sharing options...
Centurian Posted January 30, 2011 Author Share Posted January 30, 2011 Thanks, I Applied Zurevs advice: function getcomment($user,$id) { $con = mysql_connect("localhost","jameswit","Jordan"); if (!$con) { echo "Could not connect."; } $lols = mysql_select_db("jameswit_starship", $con); if (!$lols) { echo "Could not select database."; } $result = mysql_query("SELECT * FROM ".$user."Crew WHERE id = ".$id); if (!$result) { echo "No result <BR>"; echo "SELECT * FROM ".$user."Crew"; } while($row = mysql_fetch_array($result)) { if ((int)$row['loyalty']<20) { if ($row['rank']=="XO") { return $row['Name']." is openly mutinous towards you - s/he is not suitable as an XO."; goto endsub; } else { return $row['Name']." is unhappy with your leadership."; goto endsub; } } } endsub: mysql_close($con); } The Quotes were left because PHP was looking for a variable called '$userCrew' when I removed the dots, and I need to words joined with no space between them. The thing with the equals signs was just my inexperience with this language. Thanks for pointing that out. I'm still getting the same error. 'Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jameswit/www/www/MYSQL.php on line 106' Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167342 Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2011 Share Posted January 30, 2011 Why are you using goto in that function? Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167346 Share on other sites More sharing options...
Centurian Posted January 30, 2011 Author Share Posted January 30, 2011 The Goto is so I can add more if statements without getting two results. A bit superfluous though. I found the problem, and it was even earlier than any of this code. But thanks for the help. *fixed* Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167353 Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2011 Share Posted January 30, 2011 return immediately ends the execution of the function, so goto is rather useless in that context. Quote Link to comment https://forums.phpfreaks.com/topic/226127-cant-figure-this-out-second-pair-of-eyes-please/#findComment-1167356 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.