控件未输入if(isset()))

布格

下面是我的表单的html代码和我用来将数据传递给类方法的php代码。现在我遇到的问题是控件似乎没有进入我通过测试就可以得出的if循环see。“ test0”被打印,但是“ test1”和其他后续的“ test”不被打印。

 <form action="" method="post" enctype=multipart/form-data>
     <div class="form-group">
        <label for="job name">Job name:</label>
        <input type="text" class="form-control" id="jobnm" value="<?php echo $_GET['jobnm'];?>" disabled>
     </div>
     <div class="form-group">
        <label for="name">Name:</label>
        <input type="text" class="form-control" name="name" required>
     </div>
     <div class="form-group">
        <label for="email">Email address:</label>
        <input type="email" class="form-control" name="mail" required>
     </div>
     <div class="form-group">
     <label for="phone">Enter a phone number:</label><br><br>
    <input type="tel" id="phone" name="phone" placeholder="+91-1234567890" pattern="[0-9]{10}" required><br><br>
    <small>Format: 1234567890</small><br><br>
     </div>
     <label >Gender</label>
     <div class="radio">
        <label><input type="radio" name="optradio" value="m">Male</label>
    </div>
    <div class="radio">
        <label><input type="radio" name="optradio" value="f">Female</label>
    </div>
    <div class="radio">
        <label><input type="radio" name="optradio" value="o">Other</label>
    </div>
    <div class="custom-file">
        <input type="file" class="custom-file-input" name="cvFile" required>
        <label class="custom-file-label" for="customFile">Upload resume</label>
    </div>
     <button type="submit" class="btn btn-primary">Submit</button>
     <button type="reset" class="btn btn-danger" >Reset</button>
  </form>
<?php
require_once 'db-config.php';
require_once 'classCandi.php';
echo "test0";
if(isset($_POST['submit']))
{
echo "test1";
$jobID = $_GET['jobid'];
echo "test2";
$canName = $_POST['name'];
$canEmail = $_POST['mail'];
$canPhone = $_POST['phone'];
$canRadio = $_POST['optradio'];
echo "test3";
//Upload file
$fnm = "cv/";
$cvDst = $fnm . basename($_FILES["cvFile"]["name"]);
move_uploaded_file($_FILES["cvFile"]["tmp_name"],$cvDst);
echo "test4";
$obj = new Candi($conn);
$obj->storeInfo($jobID,$canName,$canEmail,$canPhone,$canRadio,$cvDst);
echo "test5";
echo '<script language="javascript">';
echo 'alert("Submitted");';
echo '</script>';
echo "test6";
}
Praveen Kumar Purushothaman

以下代码随时都不正确!这是因为您不了解其$_POST工作原理。

if(isset($_POST['submit']))

您的前端中没有输入元素name="submit"可以看到,name所有输入都没有属性。

相反,更好的方法是了解其工作原理并更改代码,使其包括:

  • name所有输入和表单元素属性。
  • 检查值而不是 $_POST['submit']

最后...

  • 不要在不理解代码的情况下进行复制和粘贴。
  • 不要检查$_POST['submit']真实性。

例如,$canName = $_POST['name'];要工作,您需要具备:

<input type="text" name="name" id="name" value="<?php echo $something; ?>" />
//                 ^^^^^^^^^^^

并在引号中添加您的属性和值:

enctype="multipart/form-data"
//      ^                   ^

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章