richiec Posted February 25, 2008 Share Posted February 25, 2008 Having a little problem here, im trying to add something to my site, with out the following part it works fine (sadly this is the part i want to add lol) so i know that it is something im missing here but its really starting to annoy me now... anyone have any ideas? heres the whole code for the part im trying to add... <?php $crewget = $_GET['crew']; if ($crewget == v1){ $getcrew = "v1"; } elseif ($crewget == v2t){ $getcrew = "v2t"; } elseif ($crewget == v2s){ $getcrew = "v2s"; } elseif ($crewget == v3){ $getcrew = "v3"; } else $getcrew = "fail"; include('db.php'); mysql_connect($server,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM `splits`"; $result=mysql_query($query) or die(hmm); $query="SELECT * FROM `splits` WHERE `crew` = '$getcrew' ORDER BY (id) ASC"; $result=mysql_query($query) or die(hmm); $num = mysql_num_rows($result); $i=0; if ($num < 1){ echo " "; } else { $splitname = mysql_result($result,$i,"splitname"); $name = mysql_result($result,$i,"name"); $godname = mysql_result($result,$i,"god"); $launch = mysql_result($result,$i,"launch"); $crew = mysql_result($result,$i,"crew"); echo "=============================== <br> $god - $launch - ($crew) <br> ===============================<br>"; while ($i < $num) { $i++; echo "$splitname - $name<br>"; } echo "<br>"; ?> Any ideas? Thanks Rich Quote Link to comment https://forums.phpfreaks.com/topic/92812-parse-error-parse-error-unexpected/ Share on other sites More sharing options...
Bauer418 Posted February 25, 2008 Share Posted February 25, 2008 Try this out (cleaned up a lot); <?php $crewget = strtolower($_GET['crew']); $accepted = array('v1', 'v2t', 'v2s', 'v3'); $crewget = array_key_exists($crewget, $accepted) ? $crewget : 'fail'; include('db.php'); mysql_connect($server, $username, $password); @mysql_select_db($database) or die("Unable to select database"); $query = "SELECT * FROM `splits`"; $result = mysql_query($query) or die(mysql_error()); $query = "SELECT * FROM `splits` WHERE `crew` = '" . $getcrew . "' ORDER BY (id) ASC"; $result = mysql_query($query) or die(mysql_error()); $num = mysql_num_rows($result); $i = 0; if ($num < 1) { echo "No results returned"; } else { $splitname = mysql_result($result, $i, "splitname"); $name = mysql_result($result, $i, "name"); $godname = mysql_result($result, $i, "god"); $launch = mysql_result($result, $i, "launch"); $crew = mysql_result($result, $i, "crew"); echo "=============================== <br>$god - $launch - ($crew) <br> ===============================<br>"; while ($i < $num) { $i++; echo "$splitname - $name<br>"; } echo "<br>"; } ?> If you still get an error, please post the the lines causing the error here. Quote Link to comment https://forums.phpfreaks.com/topic/92812-parse-error-parse-error-unexpected/#findComment-475474 Share on other sites More sharing options...
richiec Posted February 25, 2008 Author Share Posted February 25, 2008 lol yeah it was abit of a mess sorry.. and i never got the hang of using arrays but anyways... I tried that, still get the Parse error: parse error, unexpected $ in ... on line 217 line 217 is the end of the page, just a blank line =\ ive had these errors before just to find out that is just a missing ; somewhere but i cant find one so i figured this must be something else =\ any more ideas Quote Link to comment https://forums.phpfreaks.com/topic/92812-parse-error-parse-error-unexpected/#findComment-475477 Share on other sites More sharing options...
KrisNz Posted February 25, 2008 Share Posted February 25, 2008 In your original code, the last else block was missing a closing brace. That's probably still the problem (though maybe not the exact same one since it was fixed by Bauer418). This is one reason for using consistent indentation. Quote Link to comment https://forums.phpfreaks.com/topic/92812-parse-error-parse-error-unexpected/#findComment-475481 Share on other sites More sharing options...
Bauer418 Posted February 25, 2008 Share Posted February 25, 2008 After looking over the code (I may have missed something) I'm thinking that the problem isn't in this snippet, but rather in the way you are including it within your site. I did notice an error I made in my own coding, however. This line: $crewget = array_key_exists($crewget, $accepted) ? $crewget : 'fail'; Should read: $crewget = in_array($crewget, $accepted) ? $crewget : 'fail'; Quote Link to comment https://forums.phpfreaks.com/topic/92812-parse-error-parse-error-unexpected/#findComment-475490 Share on other sites More sharing options...
richiec Posted February 25, 2008 Author Share Posted February 25, 2008 I solved it, thanks for your help, ended up using a mix of my original code and yours and yes the missing { } on the last else was the problem... Thanks again Rich Quote Link to comment https://forums.phpfreaks.com/topic/92812-parse-error-parse-error-unexpected/#findComment-475520 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.