Getting Error In Small Function.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
same2cool
Forum Newbie
Posts: 11
Joined: Tue Sep 24, 2013 5:05 am
Location: Lahore, Pakistan
Contact:

Getting Error In Small Function.

Post by same2cool »

Hi Friends I am newbie and learning php.
I am getting error in variables.
please check it and define
  • What is error
  • How to resolve it
  • How to use that function properly

Code: Select all

 <?php $a=100;
                            $b=50;
                            $c=50;
                            $a+$b+$c=$d;
                            echo "$d = is the right answer." ?> 
One More Code

Code: Select all

 <?php echo "<b>What is Your Name? <br />";
                            $name=100; Here I have Error
                            $name=samee;
                            echo "My Name is $name." ?> 
In 2nd , samee should replace by 100, but it is giving error. Why?

Please Check Last 2 functions; I made comment there.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Getting Error In Small Function.

Post by Celauran »

Strings need to be enclosed in quotes.

Code: Select all

$name = "samee";
priyankagound
Forum Commoner
Posts: 27
Joined: Thu Sep 19, 2013 2:53 am

Re: Getting Error In Small Function.

Post by priyankagound »

your solutions for first code is:

<?php
$a=100;
$b=50;
$c=50;
$d=$a+$b+$c;
echo "$d = is the right answer.";
?>
Just run it, its solved.

Well in your second code there is a "." after the variable $name which should be removed.
Hope your problem is solved.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Getting Error In Small Function.

Post by Celauran »

priyankagound wrote:Well in your second code there is a "." after the variable $name which should be removed.
What?
same2cool
Forum Newbie
Posts: 11
Joined: Tue Sep 24, 2013 5:05 am
Location: Lahore, Pakistan
Contact:

Re: Getting Error In Small Function.

Post by same2cool »

Celauran wrote:Strings need to be enclosed in quotes.

Code: Select all

$name = "samee";
thanks for it. I discussed with my teacher, yes told me about it. :banghead:
same2cool
Forum Newbie
Posts: 11
Joined: Tue Sep 24, 2013 5:05 am
Location: Lahore, Pakistan
Contact:

Re: Getting Error In Small Function.

Post by same2cool »

priyankagound wrote:your solutions for first code is:

<?php
$a=100;
$b=50;
$c=50;
$d=$a+$b+$c;
echo "$d = is the right answer.";
?>
Just run it, its solved.

Well in your second code there is a "." after the variable $name which should be removed.
Hope your problem is solved.
right, that "." was for concatenate . anyway. but you did not underline my error in 2nd code that is

Code: Select all

$name="Samee";


like it. i hope you will remember it.
same2cool
Forum Newbie
Posts: 11
Joined: Tue Sep 24, 2013 5:05 am
Location: Lahore, Pakistan
Contact:

Re: Getting Error In Small Function.

Post by same2cool »

Celauran wrote:
priyankagound wrote:Well in your second code there is a "." after the variable $name which should be removed.
What?
I don't think so it is an error as
we write.

Code: Select all

<?php
$name="Sam";
echo 'My nick name is ' . $name
?>
Post Reply