dongquanjie9328 2013-04-28 20:46
浏览 16
已采纳

我用POST创建了一个不起作用的脚本[关闭]

My first code was as follows. Please tell me whats the problem test.php

   <html>
    <title>Speaker</title>
    <body>
    <form action="welcome.php" method="post" enctype="multipart/form-data">
        Name: <input type="text" name="name">
        Number: <input type="text" name="number">
        <input type="submit">

    </body>
    </html>

Welcome.php

<?php
if(isset($_POST["number"]))
{$_POST["number"]=$number;}
if(isset($_POST["name"]))
{$_POST["name"]= $name;}
if($number<33)
{echo "hello" "$name" "you have been failed" ;
    } 
?>

This script is not working. Please tell me where the problem is.

  • 写回答

4条回答 默认 最新

  • duanmengsuo9302 2013-04-28 20:47
    关注

    You are setting your variables backwards. It should look like:

    if( isset($_POST["number"]) ){
       $number = (int) $_POST["number"];
    }
    if( isset($_POST["name"]) ){
       $name = $_POST["name"];
    }
    if( isset($number) && $number<33 ){
        echo "hello {$name} you have been failed";
    }
    

    I would also recommend using a more standard if/else style like in my example, it is easier to read in larger statements. There was also a bug in your echo, you need to concatenate the string with a . or put the variable inside double quotes using curly braces. You would want to check for $number being set (if it isn't in the $_POST then it will generate a warning in your if statement).

    Lastly you want to make sure you are converting your inputs to the proper type, and sanitizing them to protect against SQL injections, cross site scripting, and other attacks (this is not shown in my example).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试