NameSilo

Just started PHP

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch
Impact
19
Hey
I just started some php tutorials and i just tried coding this

<html>
<body>
<?php
$zubair0="1";
$zubar01="2";
$zubair="$zubair0+$zubair01";
print "Hi" . " " $zubair; ?>
</body>
</html>

but the code didnt work
can u tell me what i did wrong since its not working

see it for urself

http://extremewebsitehost.com/testing.php
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
print "Hi" . " " $zubair; ?>

you either need a . after the space... like so:

print "Hi" . " " . $zubair; ?>

----------------------------

...or you can use:

print "Hi " . $zubair; ?>

(put a space after the Hi, and eliminate the need to add an extra one before the variable)
 
0
Close
Okay i tried this

<html>
<body>
<?php
$zubair0="1";
$zubar01="2";
$zubair="$zubair0+$zubair01";
print "Hi" . " " . $zubair ; ?>
</body>
</html>

it worked but it still doesnt add zubair0 and zubair01

it just shows Hi +

I also tried doing some css wid it and it didnt work either



<html>
<style type="text/css">
p {color: red}
p2 {color: blue}
</style>

<body>
<p>Example 1:
<?php
// This is the starting Tag for PHP//
$txt="Apka Future is the best";
// This declairs TXT as a veriable//

<p2> echo $txt;
// This PRINTS/excecutes the VARIABLE//
?>
</body>
</html>

www.extremewebsitehost.com/1.php

Thanks for ur HELP..i m so excited to learn PHP now :p
 
0
Close
are you trying to get it to display 3 or 12 for the first prob?
 
Last edited:
0
Close
3 :P

But making it display 12 would be kool too :)

+ can u reffer me to a PRACTICAL tutorial site for newbie's like myslef :P
i learn more by PRACTICAL tutorials than just big ebooks :p
 
0
Close
I've fixed the second problem..... there was 2 problems with the code

A) the P tags weren't closed
B) in PHP, you can't use HTML tags as they are, you either have to close the php ( ?> ) or you can echo the tag.... anyway here's the code:


Code:
<html>
<style type="text/css">
p {color: red}
p2 {color: blue}
</style>

<body>
<p>Example 1:</p>
<?php
// This is the starting Tag for PHP//
$txt="Apka Future is the best";
// This declairs TXT as a veriable//

echo '<p2>'; 
echo $txt;
echo '</p>'; 
?>
</body>
</html>

PS: Sorry i accidentaly deleted one of the comments :(

http://www.w3schools.com/php/default.asp

has a few good lessons you could learn, but no real tutorials for creating one thing... its good for learning and for reference though
 
0
Close
Okay thanks

what abt the first one?

Where did u learn PHP from :P

anyway Dreamweaver has php right?
just like it makes HTML easier, does it make PHP easier too?
is there a site that teachs PHP in dreamweaver {proabably easier}
 
0
Close
W3schools is good to start things out. But remember you do not need the double quotes when you defining integers.I mean:

$number1 = 1;
$number2 = 2;

that's the standard. for strings you use (double quotes) or (single quotes)
also.. the variable does not need to be surrounded by quote

$total = $number1 + $number2; // this will work
echo $total;
 
1
Close
yeah, i edited that on my server and it still didn't work.... i've fixed it now....

take a closer look at the variable name you have used to define "2".....

$zubar01=2;

it should be zubaIr01

also as DesignPorte said, you need to get rid of the quotation marks when defining numbers

-------------------------------------------

I've never really used dreamweaver for PHP, so im not sure

-------------------------------------------

And one final note lol, i didn't really learn PHP, i learnt the basics from making stuff like guestbooks etc, the rest i just work out
 
0
Close
alot of problems now

<html>
<body>
<?php
$zubair0=1;
$zubar01=2;
$zubair=$zubair0 + $zubair01;
print "Hi" . " " . $zubair ;
echo "<br>"
print "IF and else statement";
$d=date("D");
if ($d=="thu")
echo " Today is Thursday";
else
echo " " . " " . "Today is not Thursday bro";

?>


</body>
</html>

1. It still doesnt add
2. Today is THURSDAY but it says the other message :p
check it here:
http://extremewebsitehost.com/testing.php

Right now its giving this error too


Parse error: parse error, unexpected T_PRINT, expecting ',' or ';' in /home/unkgiver/public_html/testing.php on line 9
 
0
Close
two secs i'll look at the second part in a mo..... for the first part you need to change

$zubar01=2;

to

$zubair01=2;

(you missed the "I")
 
0
Close
Done
here is the updated code

<html>
<body>
<?php
$zubair0=1;
$zubair01=2;
$zubair=$zubair0+$zubair01;
print "Hi" . " " . $zubair ;
echo "<br />"
print "IF and else statement";
$d=date("D");
if ($d=="thu")
echo " Today is Thursday";
else
echo " " . " " . "Today is not Thursday bro";

?>


</body>
</html>

Thanks..
ps. where did u learn the Guest book part :p
 
0
Close
i got a few templates and worked out how to make my own from that..... i stored the messages to a text file.

---------------------------------

if ($d="thu")
echo "Today is Thursday";
else
echo "Today is not Thursday bro";


Im not sure if it works when the day isn't thursday though
 
0
Close
Hey thanks
some NP$ donated

okay now how do i add a SPACE

<html>
<body>
<?php
$zubair0=1;
$zubair01=2;
$zubair=$zubair0+$zubair01;
print "Hi" . " " . $zubair<br /> ;
print "IF and else statement";
$d=date("D");
if ($d="thu")
echo "Today is Thursday";
else
echo "Today is not Thursday bro";

?>


</body>
</html>
But it didnt work :p
 
0
Close
If its giving

. "<br>"

rather than just

<br>

you close the quotation marks for the variable, but you haven't opened them again for the html tag



i gotta go for dinner now so i may not reply for a few mins
 
0
Close
Is the problem solved? if not...Try this :

Code:
<html>
<body>
<?php

$zubair0=1;
$zubair01=2;
$zubair=$zubair0+$zubair01;

print "Hi" . " " . $zubair;
echo '<br />';

print "IF and else statement";
echo '<br />';

$d=date("D");

if ($d="thu")

echo "Today is Thursday";
else
echo "Today is not Thursday bro";

?>


</body>
</html>
 
0
Close
awesome
it worked

ok wt does this mean

$d=date(D)

i know $d=date means that this varibale is date
but whats the bracket D for?
 
0
Close
the D just tells the function to only collect the Day
 
0
Close
wt if i want it to colllect the time? or date?

and if i want it to show the day...i would have to use this right
$d=date(D);

echo $d;
 
0
Close
http://uk.php.net/date

there's a table on there with all the allowed letters, and a little description how to use it

yes, thats right :)
 
1
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back