PHP forum

Parsing Error

May 22, 2009 6:21 am
Lan Mind

Hello,

I'm getting :

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/l/a/
n/lanmind/html/lanmindphp.php on line 60

Line 60:

mysql_query("UPDATE answers SET answer= '$userinput' WHERE id=
'$_SESSION['selectedid']'");

I know it has to do with the session array and I'm wondering if I
remove the single quotes around 'selectedid' will it function ok?

May 22, 2009 7:55 am
J.ke?ler
Re: Parsing Error

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lan Mind wrote:
> Hello,
>
> I'm getting :
>
> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
> expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/l/a/
> n/lanmind/html/lanmindphp.php on line 60
>
> Line 60:
>
> mysql_query("UPDATE answers SET answer= '$userinput' WHERE id=
> '$_SESSION['selectedid']'");
>
> I know it has to do with the session array and I'm wondering if I
> remove the single quotes around 'selectedid' will it function ok?
Hello,

It is okay to write this line the way you do it.

But as you can see it can lead to problems and errors.

There is a much safer way. Alhough some more to code but you avoid such errors.


mysql_query("UPDATE answers SET answer= '".$userinput."' WHERE id=
'".$_SESSION['selectedid']."'");

As you can see I end the Sting with " and add the variable with the . operator
and start the string again.

Also read somethin about sql injections. Your code can easily be exploited and
the mysql database deleted.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoWWnMACgkQE++2Zdc7EtcVXwCdHrz89ZDAXGPq+a8tQAKhfp5R
zZAAnRto6jXxSC7wqNpeqh476GXLNtzd
=tasy
-----END PGP SIGNATURE-----


May 22, 2009 9:04 am
?lvaro G. Vicario
Re: Parsing Error

Lan Mind escribi?:
> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
> expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/l/a/
> n/lanmind/html/lanmindphp.php on line 60
>
> Line 60:
>
> mysql_query("UPDATE answers SET answer= '$userinput' WHERE id=
> '$_SESSION['selectedid']'");
>
> I know it has to do with the session array and I'm wondering if I
> remove the single quotes around 'selectedid' will it function ok?

Wrap your array in brackets:

mysql_query("UPDATE answers SET answer= '$userinput' WHERE
id='{$_SESSION['selectedid']}'");

http://es2.php.net/manual/en/language.types.string.php#language.types.string.parsing



-- http://alvaro.es - ?lvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programaci?n web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--


Previous Thread: PHP Question: passing objects by using an array
Next Thread: Slice a mulitdimensional array?

Related Forum Topics
Parsing Error
In my attempts to modify an existing site I now own, I've tried to
implement ideas I've been getting here...and I have a new problem. In
the following code I get a "Parse error", and I can't determine why or
what to fix. The code below represents the minimum code that produces
the...
[WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from ...
<?php
$client = new SoapClient('https://demo.docusign.net/API/3.0/
Credential.asmx?WSDL');
?>

That PHP file gets me the following errors:

http://pastebin.com/b3xQBLXD

If there wasn't anything at that URL that would be the problem, but as
is, there is a WSDL XML at that URL. Going to...
Tokan error & 401 fatal error while running google analytics API codeon dedicated server
Hi,


My trying a code to get page visits of all domains of my google
analytics account. My code is running properly on local xampp server &
i am getting visits for all domains but when i run the same code on
dedicated server. It gives me error as

401
Fatal error: Uncaught exception...
Custom error-handling creates "500 internal server error"
Hi there,

For AJAX-calls I'm buffering my output, check for errors and if an error occurred print a custom, json-formatted error message. If everything works as expected, the buffered output is printed. I don't send any headers in my script, but for some reason if an error occurs and my...
Re: Custom error-handling creates "500 internal server error"
I'm sorry I don't get it. Does that mean I cannot use ob_xx functions in the register_shutdown_function callback? Because it *does* work, except it sends a 500 header. Also, if there aren't any errors and ob_end_flush(); is called, a 200 OK header is sent.


XML parsing problem


Hello Guys,

I have a problem related to XML parsing , I am sending some XML data
in soap envelope using php .

The response I get is given below

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope...
Need help with JSON parsing with PHP
I have a script that generates a *very long* JSON string and then
(tries to) parse it with PHP using json_decode().

Unfortunately, json_decode is returning false. I am running PHP
5.2.8.

phpinfo() tells me:

json support enabled
json version 1.2.1

Upgrading to PHP 5.3.0 is not an...
Issue with a xml parsing
Hi there. Anyone capable of telling me WHY I just get 3 data outputs
from the feed in my code below?


<?php

// read xml file into string
$text = file_get_contents("http://ads-cdn.unibet.com/orval/feed/
PokerTournaments.xml");

if(!$text) {
die("ERROR: Unable to read file");
}

//...
DOM parsing problems
Hi everyone

I try to search and replace some keywords in a HTML content but I don't
want to replace words inside some links, or inside some tag definitions.
I want to match only the real content which is not between some <a ...>
</a> tags.

So I considered the DOM...
SimpleXML parsing need help
So I just don't get it.

here is a part of the xml code:
......
<weather>
<date>2010-02-11</date>
<tempMaxC>4</tempMaxC>
<tempMaxF>40</tempMaxF>
........

i can get the date with
echo " date",$xml->weather[0]->date;

so how comes that i can't get

echo " max temperatura...