Getting Parse Error While Using Two Functions [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 am trying to write a program using Call By Reference to calculate the area but I am getting a Parse Error :-
Parse error: syntax error, unexpected 'ar' (T_STRING) in C:\xampp\htdocs\workspace.php on line 7
Now I, cannot think why it is happening?
<?php
function perimeter(&$l,&$b,&$result)
{
$result=2*($l+$b);
}
funtction ar(&$le,&$br,&$result1)
{
$result1=$le*$br;
}
$result=1;
$length=$_GET['length'];
$breadth=$_GET['breadth'];
echo "<h1><center>Area And Perimeter Calculator Using Call By Reference</h1></center>";
$result = perimeter($length,$breadth,$result);
echo "<br />The Perimeter Of The Rectangle Is <strong>$result</strong>";
$result= ar($length,$breadth,$result);
echo "<br /><br />The Area Of The Rectangle Is = <strong>$result</strong>";
?>

You misspelled function:
funtction ar(&$le,&$br,&$result1)
{
$result1=$le*$br;
}
should be
function ar(&$le,&$br,&$result1)
{
$result1=$le*$br;
}

Related

generating number between 1 to million syntax error [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 6 years ago.
Improve this question
This code
<? php
$randdnumber = rand(1, 1000000);
echo "you won ".$randnumber."points";
?>
gives me error
syntax error, unexpected '$randdnumber' (T_VARIABLE) in index.php
also how to add output of two function together something like ..
You won [$randdnumber] also you won [$randdnumber2]
is it possible ?
FIXED CODE
<?php
$randdnumber = rand(1, 1000000);
echo "you won ".$randdnumber."points";
?>
fix php tags and changed variable name
FIXED
<?php
$randnumber = rand(1, 1000000);
echo "you won ".$randnumber."points";
?>
The exact problem is your php open tag is having space and also variable name you assigned and echoed are different :
Please remove it and change it to
<?php
$randdnumber = rand(1, 1000000);
echo "you won ".$randdnumber."points";
?>

Fatal error: Can't use function return value in write context in [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 6 years ago.
Improve this question
I'm getting this error and I can't make head or tail of it.
The exact error message is:
function kdrusha_theme_create_page() {
require_once(get_template_directory().= '/inc/pages/kdrusha-settings.php');
}
add_menu_page("KD Rusha Options", 'KD Rusha', 'manage_options', 'kdrusha-options', 'kdrusha_theme_create_page','',99);
The problem is that you're using .=.
something .= something_else
is shorthand for
something = something . something_else
But your something is a function call, and it generally doesn't make sense to assign to a function call (the exception is when it returns a reference).
You should just use ., which concatenates its parameters and returns the result without assigning it anywhere.
require_once(get_template_directory() . '/inc/pages/kdrusha-settings.php');
You need to put your function return in some variable:
function kdrusha_theme_create_page() {
$template = get_template_directory();
require_once($template.'/inc/pages/kdrusha-settings.php');
}

Error: Unexpected $this in PHP Code [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 7 years ago.
Improve this question
I have two PHP scripts, dispatcher.php and processor.php (there are more, but I've commented the others out because they're not necessary at the moment).
I get the following error:
Parse error: syntax error, unexpected '$this' (T_VARIABLE) in /----home directory-----/classes/processor.php on line 12
Here's the code for processor.php:
class Processor{
protected $player;
protected $name;
protected $id;
function __construct(){
}
function loadvars($request){
$this->loadvar($this->name, $request, "name");
}
private function loadvar($target, $request, $name){
if(isset($request[$name])){
$target = $request[$name];
}
else{
$target = "";
}
}
}
this is the code for dispatcher.php:
require('classes/processor.php');
$test = new Processor();
$test->loadvars($_GET);
I don't see why this error occurs?
I'm coding using Sublime on Windows, if that matters.
Fixed it!
Try retyping the file if you have weird parse errors. I copied the code back from StackOverflow (where I typed it above) and it worked. Guess some unparseable character got into the file somewhere.

How to get a value from nested array? [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
Trying to fetch the first URL field from an array of them that comes from a JSON I have decoded but I get this error:
Parse error: syntax error, unexpected '[' in C:\blabla
foreach($data-> images as $data2) {
print_r(images[0]['url']);
}
I hope its enough of my code to work out what I am doing wrong?
Added: I would like the first "url" and it was getting the last one hence why I am changing the code and trying to debug it here.
Within your foreach you use the variable name you specified in the definition:
So something like...
foreach($data->images as $data2) {
print_r($data2[0]['url']);
}
Although, depending on the structure of the array, I'd imagine that you don't need the number, so it might be:
foreach($data->images as $data2) {
print_r($data2['url']);
}
If you wanted to loop through the values by a number, you'd use a for loop
for ($i = 0; $i <= count($data->images); $i++)
{
print_r($data->images[$i]);
}

Error in trying to Upload 3 images [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
Hello i'm new in PHP and i'm trying to upload 3 images and i got an error
Please don't downgrade me i'm just learning and trying to make a simple system. Thank you
Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\epushmoyan\customer\connect.php on line 17
Here's my code :
function addpost($a,$b,$c,$d,$name,$type,$size,$tmp_name,$error,$name1,$type1,$size1,$tmp_name1,$error1,$name2,$type2,$size2,$tmp_name2,$error2,$e)
{
$img = 'thumbnails/products/'.$name.$name1.$name2
mysql_query("INSERT post(p_name,p_contact,p_email,image,image1,image2,p_address,dateadded) values ('$a','$b','$c','$d','$img','$e',NOW())");
if ($error > 0)
{
die("Error uploading file! Code $error.");
}
else
{
if($size> 10000000000) //conditions for the file
{
die("Format is not allowed or file size is too big!");
}
else
{
move_uploaded_file($tmp_name,$tmp_name1,$tmp_name2,"thumbnails/products/".$name.$name1,$name2);
}
}
Missing ;:
$img = 'thumbnails/products/'.$name.$name1.$name2
^--- here
mysql_query
Voting to close, since it's a simple typo.
Missing ; in
$img = 'thumbnails/products/'.$name.$name1.$name2

Categories