Jump to content

Parse error: parse error, unexpected $


richiec

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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';

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.