donglu2523 2016-10-07 15:03 采纳率: 100%
浏览 58

表单提交不起作用 - PHP

I'm working on a form validation and I'm currently doing some debugging on my code. I'll insert the necessary code snippets below:

Form code:

echo '<h1> Seismic Recording </h1>
<div>
<form action="validate2.php" method="POST">';

echo "Latitude: <input type='text' name='latitude'>";
echo "Longitude: <input type='text' name='longitude'required>";
echo 'Wave Type: <select id="wave_type" name="wave_type" required>
        <option selected value="s">S</option>
        <option value="p">P</option>
        <option value="surface_wave">Surface Wave</option>
        </select>';
echo "Wave Value: <input type='text' name='wave_value' required>";
echo 'Upload CSV File: <input type="file" name="file">';
echo " <input type='submit' name='submit' value='submit'>";
echo "</form>
</div> ";

Validation code:

echo "w";

if (isset($_POST['submit'])) {
    echo "t";
    $latitude = $_POST['latitude'];
    if ($latitude  == NULL) {
        echo "Please insert a latitude . <br>";
        $error = $error + 1;
    }
}

echo "q";

The form validations that I've put within the if statement doesn't work. I tried debugging the code by inserting the 'echo "q"' and 'echo "w"' to see where the problem lies. Those statements work (they output the characters). But the 'echo "t"' within the if statement doesn't work. Why is that so?

Result of var_dump($_POST):

array(5) { ["latitude"]=> string(0) "" ["longitude"]=> string(1) "g" ["wave_type"]=> string(1) "s" ["wave_value"]=> string(1) "g" ["file"]=> string(0) "" }

My issue isn't so much in getting the latitude to validate but why doesn't the 'echo t' work?

  • 写回答

5条回答 默认 最新

  • dty5753 2016-10-07 15:28
    关注

    Why check for a 'submit' post variable when you're working with latitude?

    if(isset($_POST['latitude']))
    {
         echo "t";
         $latitude=$_POST['latitude'];
    }
    else
    {
         echo "Please insert a latitude . <br>";
         $error = $error + 1;
    }
    

    Also there is no need for a name on the submit button

    <input type="submit" value="Submit">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗