PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /public_html/path1/path2/ on line 10
Introduction: I am building a PHP text messaging service. Db connect to mysql, script selects the user information from the database and uses it to send the sms to that person.
PHP Code:
<?php $con = mysql_connect("localhost","friendko_admin","Macbookpro17#"); if (!$con) { die('Could not connect: ' . mysql_error()); }
$query = "SELECT id, email, key FROM friendko_text WHERE key = $_POST['key']";
Either break from the string and apply the variable through standard evaluation, or wrap the complex type with {} to evaluate them within a string.
It appears that you have whitespace preceding your code as well. You may want to remove that if you decide to use sessions, cookies, or redirection headers (which you have used), as they will only work if output buffering is enabled at a system level. I can't be 100% sure its there, but my count puts your error on line 9, not 10.
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
That should work, and even without error if I'm not mistaken.
But I don't like that. The 'key' in my eyes is now a constant which should be a string.
What I mean is to do as:
PHP Code:
$query = "SELECT id, email, key FROM friendko_text WHERE key = {$_POST['key']}"; // or $query = "SELECT id, email, key FROM friendko_text WHERE key = " . $_POST['key'];
__________________
<DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
<DmncAtrny> And then hurl it through the window of a Sony officer
<DmncAtrny> and run like hell
It will, the issue that PHP is having is the use of [''] inside of the string where it is aware that you have a complex datatype but isn't sure how to deal with it now (since strings are scalar). Best I know it actually does so without error since the inner associate index is already a part of a string, so it should work without triggering an undefined constant error.
Still, I don't like it, and never have. I prefer the complex evaluation or the print formatters.
Edit:
Sorry it won't, missed your example quotations. The inner ones are the problem, they can be removed without error.
Possibly though after the final "' you'd need another " to terminate the string.
Quote:
Originally Posted by nomanic
or {$_POST['key']}
It its still inside a double quoted string, again yes, possibly.
I only say possibly because its one of 3 different methods that would work. I used the simplest / easiest to understand method earlier. Fou isn't keen on the in-string (as I call it) method whereas I find it rather useful and it saves a few seconds to type.
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
I didnt see
you took the quotes out of your suggestion
thats why I was confused
I didint think it would work with them in, but you took them out!
sorry!
__________________
<DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
<DmncAtrny> And then hurl it through the window of a Sony officer
<DmncAtrny> and run like hell
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
else if ($carrier == "verizon") { $formatted_number = $to."@vtext.com"; mail("$formatted_number", "SMS", "$message"); // Currently, the subject is set to "SMS". Feel free to change this.
If key is a string then enclose the value in apostrophes:
PHP Code:
$query = "SELECT id, email, key FROM friendko_text WHERE key = '{$_POST['key']}'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC))
If you are only using $row as an associative array that it is better to explicitly return such an array by specifying MYSQL_ASSOC (or use mysql_fetch_assoc()).
But I'm not sure about the re-direction. Use echo $to; etc. to check these values.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Last edited by AndrewGSW; 09-03-2012 at 12:43 AM..
$_POST['key'] will always be empty. You have no form input with name="key". You probably got some kind of key from the place letting you use their SMS service that you need to provide to their api.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||