How to Html Input value echo in php

时间:2017-07-08 15:43:40

标签: php html5 css3

I have made some classes in css and i have a html form and i also have some html elements and i want to echo them by php but i want them to echo by the value of html form submition For eg

    <form action="index.php"  method="post">
<select name="slideNumber">
 <option value="3" name="slideNumber">3 Image Slider</option>
<option value="right-3" name="slideNumber">3 Image Right Slider</option>
<option value="4" name="slideNumber">4 Image Slider</option>
<option value="right-4" name="slideNumber">4 Image Right Slider</option>
<!--And more just like this-->
</select>
<input type="submit" value="submit" />
</form>

<?php 
 $i= trim($_POST['slideNumber']);
if(($i = '3') || ($i = 'right-3')){
     $x= '3';
}
else if(($i = '4') || ($i = 'right-4')){
     $x= '4';
}
echo "
         <div class=\"slider-".$x."\">
         </div>
";
?>

It is showing only first $x I mean it is showing slider-3 even if i had give the value 4 in form please help me to solve this

2 个答案:

答案 0 :(得分:0)

基本上问题在于平等检查,即你的条件

使用:

if ($i === '3' || $i === 'right-3'){
   $x = '3';
} elseif ($i === '4' || $i === 'right-4)) {
   $x = '4';
}

答案 1 :(得分:0)

此外,您应首先通过isset检查POST数据的值...

if (isset($_POST['slideNumber']))
{}