Unexpected in error in script

I just created an form asking users to input three colors in 3 different boxes named as R ,G,B respectively.
the corresponding SCRIPT is:

An interactive color sampler

An interactive color sampler

<?php $r=$_GET['r']; $g=$_GET['g']; $b=$_GET['b']; $rgb=$r.','.$g.'.'.$b; ?> R:<?php echo $r; ?> G:<?php echo $g; ?> B:<?php echo $b; ?>

ERROR :::

Notice: Undefined index: r in C:\xampp\htdocs\display.php on line 8

Notice: Undefined index: g in C:\xampp\htdocs\display.php on line 9

Notice: Undefined index: b in C:\xampp\htdocs\display.php on line 10
R:G:B:

Hi kushal,

Seems like your variables $r, $g and $b are not set. Try to echo its values first and see if it gets printed.

Also, you’re using GET to fetch form data so I assume you have declared GET in your form’s method.

Or do you mind post your code here?

i have echoed all three variables and they are showing .but the problem is that the $rgb variable is not showing its effect .

here’s the html coding for the same :-

An interactive color sampler

An interactive color sampler

R:

G:

B:

Try adding the following to the script PHP script and post the results here

print(var_export($_GET));

Sorry, that should read

print(var_export($_GET, true));

Can’t find the edit button ???

array ( ‘r’ => ‘255’, ‘g’ => ‘105’, ‘b’ => ‘0’, )R:255
G:105
B:0

@steamindeamon ----i posted as u told but what is the use of it ?

The reason for using that code is to see if anything is being passed into those variables. From what you posted, it looks like your variables are being populated - they weren’t before. Are you still seeing a problem? You can remove the code I suggested adding as it was just for debugging.

okay but that can be checked in URl only as i had used GET method.
anyhow good alternative. my code is still not working ?

[php]

An interactive color sampler

An interactive color sampler

<?php $r=$_GET['r']; $g=$_GET['g']; $b=$_GET['b']; $rgb=$r.','.$g.','.$b; ?> R:<?php echo $r; ?> G:<?php echo $g; ?> B:<?php echo $b; ?>

asd
[/php]

You had $rgb=$r.’.’.$g.’,’.$b;
Should have been $rgb=$r.’,’.$g.’,’.$b;
Also you didn’t end the

tag

Working fine for me.

@lothop…i tried and corrected the statement $rgb=$r.’,’.$g.’,’.$b;

but this tym firefox 4.0 is asking me to take action regarding what to do with .PHP file when i submit the form.

What action is it asking you to take?
What does it say exactly.

@lothop …the download window of firefox prompts up

Please repost the code for your two pages.

Html code:

An interactive color sampler

An interactive color sampler

R:

G:

B:

script:

An interactive color sampler

An interactive color sampler

<?php $r=$_GET['r']; $g=$_GET['g']; $b=$_GET['b']; $rgb=$r.','.$g.','.$b;

?>
R:<?php echo $r; ?>

G:<?php echo $g; ?>

B:<?php echo $b; ?>

[php]$rgb=$r.’,’.$g.’,’.$b;[/php]
instead try:
[php]
$rgb=$r.",".$g.",".$b;
[/php]

it worked …thanx a lot.

no prob, those quotes can be tricky!! :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service