Parse error: syntax error, unexpected T_ELSE
Parse error: syntax error, unexpected T_ELSE
am 15.04.2008 22:49:36 von Javier Viegas
------=_Part_8721_11628227.1208292576758
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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:
*
/*
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
------=_Part_8721_11628227.1208292576758--
Re: Parse error: syntax error, unexpected T_ELSE
am 15.04.2008 23:03:40 von parasane
On Tue, Apr 15, 2008 at 4:49 PM, Javier Viegas 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:
>
> *
> /*
> 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
>
--
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
am 15.04.2008 23:56:29 von Javier Viegas
------=_Part_9083_16611420.1208296589557
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Thanks Daniel i =B4ve removed the unexpected else secction. Now it works bu=
t
it tells me that there might be a syntax error on the query, this is good
news because now i know i=B4m having connection with the database but also
there must be something wrong with the query.
$del_str =3D "DELETE FROM libros WHERE bnumero=3D".$_GET['Id'];
Is this correct, i=B4ve checked and the correct syntax to use would be dele=
te
from libros where bnumero=3D'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 wrote:
> On Tue, Apr 15, 2008 at 4:49 PM, Javier Viegas
> 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 =3D '&errorcode=3D4&';
>
> }
>
> .... 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 =3D '&errorcode=3D4&'; 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:
> >
> > *
> > /*
> > deletescore.php: deletes record for passed id from highscores table
> and
> > returns status to Flash
> > */
> > // fill with correct data for your server configuration
> > $server =3D "localhost";
> > $username =3D "root";
> > $password =3D "itsveryeasy";
> > $database =3D "biblioteca";
> >
> > //connect to database added by calm
> > mysql_connect($server, $username, $password);
> >
> > if (!mysql_connect($server, $username, $password)) {
> > $r_string =3D '&errorcode=3D1&';
> >
> > } elseif (!mysql_select_db($database)) {
> > $r_string =3D '&errorcode=3D2&';
> >
> > } else {
> >
> > $del_str =3D "DELETE FROM libros WHERE bnumero=3D".$_GET['Id'];
> >
> > if (!mysql_query ($del_str)) {
> > $msg =3D mysql_error();
> > $r_string =3D '&errorcode=3D3&msg=3D'.$msg;
> > } else {
> > $r_string =3D '&errorcode=3D0&';
> > }
> > } else {
> > $r_string =3D '&errorcode=3D4&';
> >
> > }
> >
> > echo $r_string;
> > ?>
> >
> > Wha am i doing wrong??
> >
> > Thanks.
> >
> > Javier
> >
>
>
>
> --
>
> 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!
>
------=_Part_9083_16611420.1208296589557--
RE: Parse error: syntax error, unexpected T_ELSE
am 16.04.2008 00:08:11 von Gary Wardell
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@gmail.com]
> Sent: Tue, April 15, 2008 5:56 PM
> To: php-db@lists.php.net
> 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
> wrote:
>
> > On Tue, Apr 15, 2008 at 4:49 PM, Javier Viegas
>
> > 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:
> > >
> > > *
> > > /*
> > > 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
> > >
> >
> >
> >
> > --
> >
> > 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
am 16.04.2008 18:48:26 von parasane
On Tue, Apr 15, 2008 at 5:56 PM, Javier Viegas wr=
ote:
> Thanks Daniel i =B4ve removed the unexpected else secction. Now it works =
but
> it tells me that there might be a syntax error on the query, this is goo=
d
> news because now i know i=B4m having connection with the database but al=
so
> there must be something wrong with the query.
>
>
> $del_str =3D "DELETE FROM libros WHERE bnumero=3D".$_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!).
$del_str =3D "DELETE FROM libros WHERE
bnumero=3D'".mysql_real_escape_string($_GET['Id'])."' LIMIT 1";
?>
--=20
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