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";
?>
Related
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 just need on small info i want just add '#' to one variable and and put add thing into one variable. i am adding small php code to here please suggest me.
<?php
$email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_emial.;
echo $tag_name;
?>
but i am getting only # as output;
but my out should be "#mahesh1" if any have idea about this code please help me. thank you advanced.
there is so much spelling mistakes in the variables... try below given code
<?php $email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_email;
echo $tag_name;
?>
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
Okay this really strange or I am missing something. When I run this very simmple PHP script on cmd I get the expected output which is 0. but when I uncomment the last two lines of code. . .nothing is displayed.
<?php
$test1 = 0;
echo $test1;
$test2 = 0;
#$test1_weight = 0:
#$test2_weight = 0;
?>
Is there some rule against declaring variables after an echo statement?
$test1_weight = 0:
--> change ":" to ";"
No there is no rule against declaring variables after an echo statement
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
It's a basic question, but I've googled all sorts of variations of it & nothing that quite answers me. I want to display one of two images. One if the criteria is met & one if it is not met. This code works. If criteria is met, it does display the image. But there is no alternative
<? if(stripslashes($getfeedbackQryRow['CompanyID'])=='344'){?><img src='img1.png' alt='Todays Bite'><? }?>
Then I put this together, but it's still wrong
<?PHP
if ($getfeedbackQryRow['CompanyID']) == '344') {
print ("<IMG SRC =/img1.png>");
}
else {
print ("<IMG SRC =img2.png>");
}
?>
This one looks like it should be right, but it throws an error... It's probably a syntax issue. Does anyone know what I'm doing wrong?
You have an extra ")"
if ($getfeedbackQryRow['CompanyID']) == '344') {
Remove the ")" here ['CompanyID'])
if ($getfeedbackQryRow['CompanyID']) == '344') {
// ^------- this is causing your error
You should do something simple like this:
$image_name = $getfeedbackQryRow['CompanyId'] == '344' ? 'img1.png' : 'img2.png';
echo '<img src="' . $image_name . '">';
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;
}
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
First of all sorry for the most likely simple question. I have two echo statements from woocommerce that I need to subtract from each other.
the first is
<?php echo $woocommerce->cart->get_discounts_before_tax(); ?>
This gives me the amount of the coupon discount.
The second is
<?php echo $woocommerce->cart->get_cart_subtotal(); ?>
This gives me the total off all things in the cart.
I need to subtract the coupon discount from the cart subtotal. So I set this up
<?php
$first_number = $woocommerce->cart->get_cart_subtotal ;
$second_number = $woocommerce->cart->get_discounts_before_tax ;
$sum_total = $first_number - $second_number;
print ($sum_total);
?>
but obviously the syntax is not right and I just get 0. Please help me with some simple math!
I guess you've missed ()
$first_number = $woocommerce->cart->get_cart_subtotal();
$second_number = $woocommerce->cart->get_discounts_before_tax();
Without parentheses, you're trying to access a property; but not calling the existent method itself.
Obviously one or both of the function returns are non-integers or 0. Find the return of each and change it to the appropriate property or function. Try this public property for the first number.
$first_number = $woocommerce->cart->subtotal;