whats wrong with my php code? plzz help me!

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
senahsirap
Forum Newbie
Posts: 3
Joined: Mon Feb 12, 2007 10:01 pm

whats wrong with my php code? plzz help me!

Post by senahsirap »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i wrote the code to allow user change the background color for my system. the color picker is write in javascript. but i have some problem with my .php files. 
 
file zz.php

Code: Select all

<?php

$bgColor = $_POST['backColor'];

echo $bgColor;

?>
<link rel="stylesheet" type="text/css"
media="screen" href="style.php">


<script language="JavaScript">
function BtnOkClicked()
{
document.getElementById("bgCol".value = SEL_COLOR;
}
</script>

<html>
<body>
<form method="post" action="style.php?bg=000023">
<div class="divSection">

<br>BACKGROUND:<br>
Choose A color: <input type="text" id="bgCol" size="12"><input type="button" value="..." onclick="ShowLayer();"><BR> 

<br><br>

<input name="change" type="submit" value="Change Now">

<!--COLOR PICKER WIDGET BEGIN -->
<div style="position:absolute;border:1px solid black;background-color:white;display:none;width:337px;height:375px;" id="main" imgLoc="./">
</div>
<script language="JavaScript" src="cpick.js"></script>
<!--COLOR PICKER WIDGET END -->
</form>
</body>
</html>
style.php

Code: Select all

<?php


$id = $_GET['bg'];

echo $id;


$white = $id;
$dkgray = '#333444';
$dkgreen = '#008400';
?>


body {
background:<?=$white?>;
color:<?=$dkgray?>;
}
h1, h2, h3, h4 {
color:<?=$dkgreen?>;
}
blockquote {
color:<?=$dkgreen?>;
}
the problem is when i set the value of bg= #000023 in zz.php. it can't read the '#' sign. the output that i got such as below:-
body { background:; color:#333; } h1, h2, h3, h4 { color:#008400; } blockquote { color:#008400; }

then, i try to remove the '#'. but the background color still not change. the output such as below:-
000023 body { background:000023; color:#333; } h1, h2, h3, h4 { color:#008400; } blockquote { color:#008400; }

plzz help me..i didn't know what to do. i still work on it but can't find where is the error.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Put the sign in the text instead of the code. Believe it or not, the pound sign is an alternative comment symbol.

Oh yeah, and try to stay away from short PHP tags. They will come back to bite you in the future.
senahsirap
Forum Newbie
Posts: 3
Joined: Mon Feb 12, 2007 10:01 pm

Post by senahsirap »

Everah wrote:Put the sign in the text instead of the code. Believe it or not, the pound sign is an alternative comment symbol.

Oh yeah, and try to stay away from short PHP tags. They will come back to bite you in the future.
i'm so soryy. i'm really newbie in php. what do yo mean by put the sign in the text instead of the code. which sign? and this tag '<?' that you refer as short php tag?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Something like this...

Code: Select all

<?php
$id = $_GET['bg'];
echo $id;

$white = $id;
$dkgray = '333444';
$dkgreen = '008400';
?>

body {
  background: #<?php echo $white; ?>;
  color: #<?php echo $dkgray; ?>;
}

h1, h2, h3, h4 {
  color: #<?php echo $dkgreen; ?>;
}
blockquote {
  color: #<?php echo $dkgreen; ?>;
}
senahsirap
Forum Newbie
Posts: 3
Joined: Mon Feb 12, 2007 10:01 pm

Post by senahsirap »

i had changed the code like u said. but the color still didn't change. this is the output i got:-

F00023 body { background: #F00023; color:333; } h1, h2, h3, h4 { color:008400; } blockquote { color:008400; }

i think the problem is with $id variable

when i try to change $white = '$id'; read $id as a text. this is the output:-

F00023 body { background: #$id; color:333; } h1, h2, h3, h4 { color:008400; } blockquote { color:008400; }

i only can get the ouput if i set the color value in the $white variable. for eg:- $white = 'F50021';
but i want to bring the value from the previous page, which is from page zz.php
Post Reply