Parse error: syntax error, unexpected T_ELSE

View: New views
5 Messages — Rating Filter:   Alert me  

Parse error: syntax error, unexpected T_ELSE

by Javier Carlos Viegas-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hi, i have this script wich basically connects to a database and delete a
record according to the Id parameter given. The problem is that when i test
it i get this error:

*Parse error*: syntax error, unexpected T_ELSE in *
/var/www/biblio/scripts/delete.php* on line *31

This is the script:

*<?php
/*
   deletescore.php:  deletes record for passed id from highscores table and
                     returns status to Flash
*/
// fill with correct data for your server configuration
$server = "localhost";
$username = "root";
$password = "itsveryeasy";
$database = "biblioteca";

//connect to database added by calm
mysql_connect($server, $username, $password);

if (!mysql_connect($server, $username, $password)) {
   $r_string = '&errorcode=1&';

} elseif (!mysql_select_db($database)) {
   $r_string = '&errorcode=2&';

} else {

      $del_str = "DELETE FROM libros WHERE bnumero=".$_GET['Id'];

      if (!mysql_query ($del_str)) {
         $msg = mysql_error();
         $r_string = '&errorcode=3&msg='.$msg;
      } else {
         $r_string = '&errorcode=0&';
      }
   } else {
      $r_string = '&errorcode=4&';

}

echo $r_string;
?>

Wha am i doing wrong??

Thanks.

Javier

Re: Parse error: syntax error, unexpected T_ELSE

by Daniel Brown-5 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 15, 2008 at 4:49 PM, Javier Viegas <javiercviegas@...> wrote:
> Hi, i have this script wich basically connects to a database and delete a
>  record according to the Id parameter given. The problem is that when i test
>  it i get this error:
>
>  *Parse error*: syntax error, unexpected T_ELSE in *
>  /var/www/biblio/scripts/delete.php* on line *31

    Javier,

    This block:

} else {
     $r_string = '&errorcode=4&';

}

    .... is incorrect.  You call an else condition on line 21, so PHP
expects that block to be the last for that if() condition.  Either
remove the } else { and $r_string = '&errorcode=4&'; lines or rewrite
the condition.

    And if that's your real database login information, change it and
update all of your scripts and systems ASAP.


>
>  This is the script:
>
>  *<?php
>  /*
>    deletescore.php:  deletes record for passed id from highscores table and
>                      returns status to Flash
>  */
>  // fill with correct data for your server configuration
>  $server = "localhost";
>  $username = "root";
>  $password = "itsveryeasy";
>  $database = "biblioteca";
>
>  //connect to database added by calm
>  mysql_connect($server, $username, $password);
>
>  if (!mysql_connect($server, $username, $password)) {
>    $r_string = '&errorcode=1&';
>
>  } elseif (!mysql_select_db($database)) {
>    $r_string = '&errorcode=2&';
>
>  } else {
>
>       $del_str = "DELETE FROM libros WHERE bnumero=".$_GET['Id'];
>
>       if (!mysql_query ($del_str)) {
>          $msg = mysql_error();
>          $r_string = '&errorcode=3&msg='.$msg;
>       } else {
>          $r_string = '&errorcode=0&';
>       }
>    } else {
>       $r_string = '&errorcode=4&';
>
>  }
>
>  echo $r_string;
>  ?>
>
>  Wha am i doing wrong??
>
>  Thanks.
>
>  Javier
>



--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Parse error: syntax error, unexpected T_ELSE

by Javier Carlos Viegas-2 :: Rate this Message:

| View Threaded | Show Only this Message

Thanks Daniel i ´ve removed the unexpected else secction. Now it works but
it tells me that there might be a syntax error on the query, this is good
news because now i know i´m having connection with the database but also
there must be something wrong with the query.

$del_str = "DELETE FROM libros WHERE bnumero=".$_GET['Id'];

Is this correct, i´ve checked and the correct syntax to use would be delete
from libros where bnumero='something';
Given 'something' is taken from a variable called Id it seems reasonable to
me the way it is written. Do you see anything wrong?

Thanks again.


On Tue, Apr 15, 2008 at 6:03 PM, Daniel Brown <parasane@...> wrote:

> On Tue, Apr 15, 2008 at 4:49 PM, Javier Viegas <javiercviegas@...>
> wrote:
> > Hi, i have this script wich basically connects to a database and delete
> a
> >  record according to the Id parameter given. The problem is that when i
> test
> >  it i get this error:
> >
> >  *Parse error*: syntax error, unexpected T_ELSE in *
> >  /var/www/biblio/scripts/delete.php* on line *31
>
>     Javier,
>
>    This block:
>
> } else {
>     $r_string = '&errorcode=4&';
>
> }
>
>     .... is incorrect.  You call an else condition on line 21, so PHP
> expects that block to be the last for that if() condition.  Either
> remove the } else { and $r_string = '&errorcode=4&'; lines or rewrite
> the condition.
>
>    And if that's your real database login information, change it and
> update all of your scripts and systems ASAP.
>
>
> >
> >  This is the script:
> >
> >  *<?php
> >  /*
> >    deletescore.php:  deletes record for passed id from highscores table
> and
> >                      returns status to Flash
> >  */
> >  // fill with correct data for your server configuration
> >  $server = "localhost";
> >  $username = "root";
> >  $password = "itsveryeasy";
> >  $database = "biblioteca";
> >
> >  //connect to database added by calm
> >  mysql_connect($server, $username, $password);
> >
> >  if (!mysql_connect($server, $username, $password)) {
> >    $r_string = '&errorcode=1&';
> >
> >  } elseif (!mysql_select_db($database)) {
> >    $r_string = '&errorcode=2&';
> >
> >  } else {
> >
> >       $del_str = "DELETE FROM libros WHERE bnumero=".$_GET['Id'];
> >
> >       if (!mysql_query ($del_str)) {
> >          $msg = mysql_error();
> >          $r_string = '&errorcode=3&msg='.$msg;
> >       } else {
> >          $r_string = '&errorcode=0&';
> >       }
> >    } else {
> >       $r_string = '&errorcode=4&';
> >
> >  }
> >
> >  echo $r_string;
> >  ?>
> >
> >  Wha am i doing wrong??
> >
> >  Thanks.
> >
> >  Javier
> >
>
>
>
> --
> </Daniel P. Brown>
> Ask me about:
> Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
> and shared hosting starting @ $2.50/mo.
> Unmanaged, managed, and fully-managed!
>

RE: Parse error: syntax error, unexpected T_ELSE

by Gary Wardell-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

I suggest you echo $del_str to see exactly what your query is.

There may be something unexpected in $_GET['Id'].

Echo the whole query so you can see everything in context.

Gary

> -----Original Message-----
> From: Javier Viegas [mailto:javiercviegas@...]
> Sent: Tue, April 15, 2008 5:56 PM
> To: php-db@...
> Subject: Re: [PHP-DB] Parse error: syntax error, unexpected T_ELSE
>
>
> Thanks Daniel i ´ve removed the unexpected else secction. Now
> it works but
> it tells me that there might be a syntax error on the query,
> this is good
> news because now i know i´m having connection with the
> database but also
> there must be something wrong with the query.
>
> $del_str = "DELETE FROM libros WHERE bnumero=".$_GET['Id'];
>
> Is this correct, i´ve checked and the correct syntax to use
> would be delete
> from libros where bnumero='something';
> Given 'something' is taken from a variable called Id it seems
> reasonable to
> me the way it is written. Do you see anything wrong?
>
> Thanks again.
>
>
> On Tue, Apr 15, 2008 at 6:03 PM, Daniel Brown
> <parasane@...> wrote:
>
> > On Tue, Apr 15, 2008 at 4:49 PM, Javier Viegas
> <javiercviegas@...>
> > wrote:
> > > Hi, i have this script wich basically connects to a
> database and delete
> > a
> > >  record according to the Id parameter given. The problem
> is that when i
> > test
> > >  it i get this error:
> > >
> > >  *Parse error*: syntax error, unexpected T_ELSE in *
> > >  /var/www/biblio/scripts/delete.php* on line *31
> >
> >     Javier,
> >
> >    This block:
> >
> > } else {
> >     $r_string = '&errorcode=4&';
> >
> > }
> >
> >     .... is incorrect.  You call an else condition on line
> 21, so PHP
> > expects that block to be the last for that if() condition.  Either
> > remove the } else { and $r_string = '&errorcode=4&'; lines
> or rewrite
> > the condition.
> >
> >    And if that's your real database login information, change it and
> > update all of your scripts and systems ASAP.
> >
> >
> > >
> > >  This is the script:
> > >
> > >  *<?php
> > >  /*
> > >    deletescore.php:  deletes record for passed id from
> highscores table
> > and
> > >                      returns status to Flash
> > >  */
> > >  // fill with correct data for your server configuration
> > >  $server = "localhost";
> > >  $username = "root";
> > >  $password = "itsveryeasy";
> > >  $database = "biblioteca";
> > >
> > >  //connect to database added by calm
> > >  mysql_connect($server, $username, $password);
> > >
> > >  if (!mysql_connect($server, $username, $password)) {
> > >    $r_string = '&errorcode=1&';
> > >
> > >  } elseif (!mysql_select_db($database)) {
> > >    $r_string = '&errorcode=2&';
> > >
> > >  } else {
> > >
> > >       $del_str = "DELETE FROM libros WHERE bnumero=".$_GET['Id'];
> > >
> > >       if (!mysql_query ($del_str)) {
> > >          $msg = mysql_error();
> > >          $r_string = '&errorcode=3&msg='.$msg;
> > >       } else {
> > >          $r_string = '&errorcode=0&';
> > >       }
> > >    } else {
> > >       $r_string = '&errorcode=4&';
> > >
> > >  }
> > >
> > >  echo $r_string;
> > >  ?>
> > >
> > >  Wha am i doing wrong??
> > >
> > >  Thanks.
> > >
> > >  Javier
> > >
> >
> >
> >
> > --
> > </Daniel P. Brown>
> > Ask me about:
> > Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
> > and shared hosting starting @ $2.50/mo.
> > Unmanaged, managed, and fully-managed!
> >
>



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Parse error: syntax error, unexpected T_ELSE

by Daniel Brown-5 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 15, 2008 at 5:56 PM, Javier Viegas <javiercviegas@...> wrote:
> Thanks Daniel i ´ve removed the unexpected else secction. Now it works but
>  it tells me that there might be a syntax error on the query, this is good
>  news because now i know i´m having connection with the database but also
>  there must be something wrong with the query.
>
>
>  $del_str = "DELETE FROM libros WHERE bnumero=".$_GET['Id'];
[snip!]

    You didn't enclose the value in quotes, that's all (and you should
sanitize the input --- NEVER accept data without sanitizing it
first!).

<?php
$del_str = "DELETE FROM libros WHERE
bnumero='".mysql_real_escape_string($_GET['Id'])."' LIMIT 1";
?>

--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php