PDA

View Full Version : [PHP] I can't figure this error!



Ronak
November 24th, 2004, 10:40 PM
Hello

I'm just trying to be some of the basics. I'm trying to say if the v in the url equals 1 then display 1. And so on through the rest of the code. Can you help?

This code just doesn't come out right!



<?php

$v = $_GET['v'];

if ($v = '1') {
$msg = "1";
} else if ($v = '2') {
$msg = "2";
} else if ($v = '3') {
$msg = "3";
} else if ($v = '4') {
$msg = "4";
} else if ($v = '5') {
$msg = "5";
} else {
$msg = "Add a ?v= and a number in between 1 and 5!";
}

echo $msg;

?>


Please reply back

~Ron

ironikart
November 25th, 2004, 12:13 AM
you need to use == (equality operator) not = (assignment operator)



<?php

$v = $_GET['v'];

if ($v == '1') {
$msg = "1";
} else if ($v == '2') {
$msg = "2";
} else if ($v == '3') {
$msg = "3";
} else if ($v == '4') {
$msg = "4";
} else if ($v == '5') {
$msg = "5";
} else {
$msg = "Add a ?v= and a number in between 1 and 5!";
}

echo $msg;
?>