Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
i have this bunch of code:
$field_with_lengths = array('menu', 'position', 'visible');
foreach($field_with_lengths as $field_with_lenths => $maxlength){
if(strlen(trim(mysql_prep($_POST[$fieldname]))) => $maxlength){
$errors[] = $fieldname;}
i'm getting the folowing error:
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in C:\xampp\htdocs\vp\edit_info.php on line 22
wich is: if(strlen(trim(mysql_prep($_POST[$fieldname]))) => $maxlength){
i am not managing to find anything wrong on line 22
how can i fix that up?

It's >= (greater than or equal to) not => (equal to or greater than):
if(strlen(trim(mysql_prep($_POST[$fieldname]))) >= $maxlength){

if(strlen(trim(mysql_prep($_POST[$fieldname]))) >= $maxlength){
Equal sign must come after the bracket

Related

PDO parse error unexpected ":" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to establish a new PDO instance with the following code
<?php
$handler = new PDO(“mysql:host=127.0.0.1;dbname=database”,
“root”, “”);
I get the following error message:
Parse error: syntax error, unexpected ':', expecting ',' or ')' in /Applications/XAMPP/xamppfiles/htdocs/example/connection.php on line 2
There has been no problems like this before until I attempted to do this on a new Mac. Can someone help with this issue?
try this:
$handler = new PDO("mysql:host=127.0.0.1;dbname=database",
"root", "");
your quotes were wrong
You should to this:
<?php
$handler = new PDO("mysql:host=127.0.0.1;dbname=database","root", "");

Parse error: syntax error, unexpected ']' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm getting this error:
Parse error: syntax error, unexpected ']', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in your code on line 70
Line 70 is $message.
$random_keys=array_rand($lel,1);
$message[] = $lel[$random_keys[0]];
The whole code is here:
$message = array();
$lel = array(
'Are you sure its the new year?',
'And i thought i was dumb', 'its not new year yet',
'LOL its ${date}', '...', '.....', '...', 'WUT', '.......',
'Ya drunk bruh ?', 'You sure you are not drunk ? what is 1+1 then ?'
);
$random_keys=array_rand($lel,1);
$message[] = $lel[$random_keys[0]];
Can we do it like this?
$message[] = $lel[rand(1,11)];
It still gives:
Parse error: syntax error, unexpected ']', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
You are only picking one random key here:
$random_keys=array_rand($lel,1);
So you want to do this:
$random_key = array_rand($lel,1);
$message[] = $lel[$random_key];
Working example: http://3v4l.org/PHWD8
Though, since you're only picking one random key, and one random message, do you even need $message to be an array? I'd just do this:
$message = $lel[array_rand($lel)];
Working example: http://3v4l.org/jJKrG
As for your parse error, there's something we're not seeing in the code you posted. Perhaps it is some other surrounding code, or perhaps you modified the code before pasting here? In any event, you can see that your exact code does not produce a parse error: http://3v4l.org/Io1jc

Parse error: syntax error, unexpected ':' in C:\wamp\www\xyz\contact-form.php on line 4 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I'm getting the error:
Parse error: syntax error, unexpected ':' in C:\wamp\www\xyz\contact-form.php on line 4
On a contact form that I'm trying to create for my portfolio site. I'm creating a simple check for the form submission and if it doesn't exist, it'll re-direct you back to to the index.
My code is:
if (!isset($_POST["save"]) || $_POST["save"] != ”contact”) {
header(“Location: index.php”);
exit;
}
Line 4 is the header() call, and I can't see what I've done wrong. I expect it's a small syntax error, any ideas?
The quotes aren't right, I'm assuming you copied it from a site, should be " not “
You're using funny quotes: (also known as smart quotes and curly quotes)
if (!isset($_POST["save"]) || $_POST["save"] != ”contact”) {
header(“Location: index.php”);
should be:
if (!isset($_POST["save"]) || $_POST["save"] != "contact") {
header("Location: index.php");

syntax error, unexpected T_LNUMBER, expecting ']' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am getting the following error message. Can someone please help me.
Parse error: syntax error, unexpected T_LNUMBER, expecting ']' in /home/whilesto/public_html/includes/init.php on line 61
Following is the code from line 54 to 66
if ($setts['is_mod_rewrite'])
{
$valsArray = explode(",", $_REQUEST['rewrite_params']);
$valsCnt = 0;
$count_valsArray = count($valsArray);
while ($valsCnt < $count_valsArray)
{
$_REQUEST[$valsArray[$valsCnt 1]] = $valsArray[$valsCnt];
$_GET[$valsArray[$valsCnt 1]] = $valsArray[$valsCnt];
$_POST[$valsArray[$valsCnt 1]] = $valsArray[$valsCnt];
$valsCnt = 2;
}
}
The error lies not only in line 61 but also in lines 62 and 63. You have to remove the 1 from between $valsCount and ]:
$_REQUEST[$valsArray[$valsCnt]] = $valsArray[$valsCnt];
$_GET[$valsArray[$valsCnt]] = $valsArray[$valsCnt];
$_POST[$valsArray[$valsCnt]] = $valsArray[$valsCnt];
It also seems to me that you’ve written an endless while loop. You may consider changing line 64 to:
$valsCnt++;

Parse error when using variable variables [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Here is my code inside of a function:
list(${$page}Records, ${$page}MetaData) = getRecords(array(
'tableName' => $page,
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
Problem is, the very first line of it throws this error :
Parse error: syntax error, unexpected T_STRING, expecting ',' or ')' in /[edited]/includes/functions.php on line 10
I've tried a bunch of different ways of going about this but I don't know much about PHP. Anyone know what's going on here?
${$page}Records
This is not how you use variable variables. PHP has no idea what you mean with Records there.
Try this:
${$page.'Records'}
PHP will run the code inside the {} and use that string as a variable name.

Categories