dongshi2836 2018-07-14 13:32
浏览 72

未定义的索引错误php(提交标记不输入mysql表中的信息)

I have to enter the data from a form to a database table. I created the test database and the employee table in phpMyAdmin. When I run it on localhost I get the undefined index error for variables Name, Surname..., and the submit tag doesn't upload the form info into the table in the database. How can I solve this problem?

This is my code:

page.php

<?php 
    include_once('db.php');
    $sql = " ";
    $vlere = mysqli_query($sql,$conn);
    if (isset($_POST['submit'])) {
        $Name = $_POST['name'];
        $Surname = $_POST['surname'];
        $Birthday = $_POST['birthday'];
        $Email = $_POST['email'];
        $Telephone = $_POST['telephone'];
        $Address = $_POST['address'];
        $Company = $_POST['company'];
        $Role = $_POST['role'];

        $sql = "INSERT INTO employee(Name, Surname, Birthday, Email, Telephone, Address, Company, Role) VALUES('$Name', '$Surname', '$Birthday', '$Email', '$Telephone', '$Address', '$Company', '$Role')";
        $vlere = mysqli_query($sql,$conn);
    }
    if (!empty($vlere)) {
        echo "Empty";
    }
    else {
        echo "Inserted";
    }
?>

index.html

<html>
<head>
    <title>Human Resource</title>
</head>
<body>
    <h3><center>Enter the <b>EMPLOYEE</b> information</center></h3>
    <form action="page.php" method="post">
        Name:     
        <input type="text" name="name" ></br></br>
        Surname:  
        <input type="text" name="surname" ></br></br>
        <div>
            Birthday: 
            <input type="date" name="birthday" required pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}"/>

        </div>
        </br></br>
        <div>
            Email:    
            <input type="email" name="email" size="40" maxLength="40" required  placeholder="username@gmail.com" pattern=".+@gmail.com">
        </div> 
        </br></br>
        <div>
            Telephone:  
            <input type="tel" name="telephone" max="15" required placeholder="xxx-xxx-xxxx" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}">
        </div>
        </br></br>
        <div>
            Address:  <input type="address" name="address" required />
        </div>
        </br></br>
            Company Name: 
            <form>
                <select id="company">
                    <option value="AT Consulting">AT Consulting</option>
                    <option value="IKUB.al">IKUB.al</option>
                    <option value="InfoSoft">InfoSoft</option>
                    <option value="ATOM Computers">ATOM Computers</option>
                </select>
            </form>
                Field: 
                <input type="text" id="field" />
                <button onclick="func1()">Add</button>
                <script>
                    function func1(){
                        var x = document.getElementById("company");
                        var option = document.createElement("option");
                        option.innerHTML = document.getElementById("field").value;
                        x.add(option); 
                    }
                </script>
        </br></br>
        Role: <input type="text" name="role" >
        </br></br>
        <input type="submit" name="submit" value="submit" />
    </form>
    <script src="script/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="script/first_script.js" type="text/javascript"></script>
</body>

first_script.js

$("#sub").click( function() {
$.post( $("#myForm").attr("action"), 
     $("#myForm :input").serializeArray(), 
     function(info){ $("#result").html(info); 
 });
clearInput();
});

$("#myForm").submit( function() {
    return false;   
 });

 function clearInput() {
$("#myForm :input").each( function() {
   $(this).val('');
});
 }

db.php

  <?php
      $conn = mysqli_connect('localhost', 'root', '');
      $db = mysqli_select_db('test');
  ?>

Thank you for taking your time to answer me.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c