douliang2087 2013-02-13 00:07
浏览 19

php和mysql变量

i have a web called Infomundo and under the site i have a problem with php:

$c=1;
  while($c!=17)
  { $fecha_semana$c=$_POST['fecha_semana$c'];
    $interes_semana$c=$_POST['interes_semana$c'];
    $capital_semana$c=$_POST['capital_semana$c'];
    $recargos_semana$c=$_POST['recargos_semana$c'];
    $iva_semana$c=$_POST['iva_semana$c'];
    $pagado_semana$c=$_POST['pagado_semana$c'];
    $c=$c+1;
  }

but the variables $fecha_semana$c, $interes_semana$c, etc. are wrong how can i fix it?

  • 写回答

2条回答 默认 最新

  • dpw70180 2013-02-13 00:11
    关注

    You're using single quotes in the array dereference:

    $_POST['fecha_semana$c'];
    

    That will not evaluate the value of $c; use double quotes:

    $_POST["fecha_semana$c"];
    

    See also: string

    Additionally, you need to use variable variables for the left hand of the assignment:

    ${"fecha_semana$c"} = $_POST["fecha_semana$c"];
    

    Update

    This problem would be easier if you'd use array syntax in your form fields:

    <input name="fecha_semana[]" value="123" />
    <input name="fecha_semana[]" value="456" />
    <input name="fecha_semana[]" value="678" />
    

    When that gets posted, you will have an array in PHP:

    print_r($_POST['fecha_semana']);
    // ["123", "456", "678"]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法