IT.COM

Just started PHP

Spaceship Spaceship
Watch
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
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
•••
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
•••
are you trying to get it to display 3 or 12 for the first prob?
 
Last edited:
0
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
the D just tells the function to only collect the Day
 
0
•••
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
•••
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
•••
www.l3h.net/test.php

Added where it displays the time :)

Here's the full code:
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";
echo '<br />';

$today = date("G:i:s T Y");
echo $today;
?>

</body>
</html>
 
1
•••
0
•••
G:i:s is the time in 24 hour format

T is the time zone

Y is the year
 
0
•••
okay awesome :P
I am searching google to see if i can find a tutorial that teachs u how to make specific stuff like GUESTBOOK etc..DO u know of anything like dat?
Vid tuts r BETTER
p.s: i dont wana work wid mysql..only PHP for now

2. Can i make that clock so it refreshes itself for seconds...
 
0
•••
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back