在表列中插入数字一,而不是名称,电子邮件和位置

时间:2018-09-20 13:17:53

标签: php mysql

         This is index.php   
          <?php 
            session_start();
            include_once('process.php');
            if(isset($_POST['submit']))
            {
            $fullname = isset($_POST['fullname']);
            $email = isset($_POST['email']);
            $mobile = isset($_POST['mobile']);
            $location = isset($_POST['location']);
            $program = isset($_POST['program']);
            $dateoofbirth = $_POST['day']."-".$_POST['month']."-".$_POST['year'];
            }
            ?>
            <?php 
            $fullname = isset($_POST['fullname']);
            $email = isset($_POST['email']);
            $mobile = isset($_POST['mobile']);
            $location = isset($_POST['location']);
            $program = isset($_POST['program']);
            $dateofbirth = isset($_POST['day'])."-". isset($_POST['month'])."-".isset($_POST['year']);
            ?>
        <div class="container-fluid">
        <div class="row" id="banner">
        <div class="col-md-8">
                <img src="images/images.png" style="height:500px; width:671px;">
        </div>
        <div class="col-md-4">
        <div class="container">
                <form>
                  <div class="form-row">
                    <div class="form-group">
                      <label for="name"></label>
                      <input type="text" class="form-control" id="fullname" name="fullname" value="<?php echo 
                      isset($_POST['fullname']); ?>" placeholder="ENTER NAME">
                    </div>
                    <div class="form-group">
                      <label for="email"></label>
                      <input type="email" class="form-control" id="email" name="email" value="<?php echo 
                      isset($_POST['email']); ?>" placeholder="ENTER EMAIL">
                    </div>
                  </div>
                <div class="form-group">
                 <label for="mobile"></label>
                 <input type="text" class="form-control" id="mobile" name="mobile" value="<?php echo 
                  isset($_POST['mobile']); ?>" placeholder="ENTER MOBILE NUMBER">
                  </div>
                  <div class="form-group">
                    <label for="location"></label>
                    <input type="text" class="form-control" id="location" name="location" 
                    value="<?php echo isset($_POST['location']); ?>" placeholder="ENTER LOCATION">
                  </div>
                  <div class="form-group">
                      <select class="form-control" id="program" name="program" required>
                          <option value="program"><?php echo isset($_POST['program']); ?></option>
                          <option value="PG Diploma Programs">PG Diploma Programs</option>
                          <option value="Diploma Programs">Diploma Programs</option>
                          <option value="Certificate Programs">Certificate Programs</option>
                    </select>
                   </div>
        <div class="wrapper">
        <!---<input type="submit" id= "submit" name="submit" value="Submit"/>-->
        <input type="submit" id="submit" name="submit" class="btn btn-primary" value="SEND ENQUIRY">
        </div>
        This is process.php 
        <?php
        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "myDB";
        $conn = new mysqli($servername, $username, $password, $dbname);
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        } 
        ?>
        <?php 
        if(isset($_POST['submit']))
        {
        $fullname = addslashes($_POST['fullname']);
        $email = addslashes($_POST['email']);
        $mobile = addslashes($_POST['mobile']);
        $location = addslashes($_POST['location']);
        $program = addslashes($_POST['program']);
        $dobArr = array($_POST['day']."-". $_POST['month']."-".$_POST['year']);
        $dateofbirth = implode('-',$doArr);
        date_default_timezone_set('Asia/Calcutta');
        $today = date('d-m-Y H:i:s');
        }
        $sql = "INSERT INTO enquiry(id,fullname,email,mobile,location,program,dateofbirth)
        VALUES ('', '".isset($_POST["fullname"])."', '".isset($_POST["email"])."','".isset($_POST["mobile"])."','".isset($_POST["location"])."','".isset($_POST["program"])."','".isset($_POST["dateofbirth"])."')";
        ?>
        <?php
        if ($conn->query($sql) === TRUE) {
            echo "New record created successfully";
        } 
        else 
        {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
        $conn->close();
        ?>

        inserting table data name,email,mobile ,location as value 1 .
        it should be  some name as richard ,richard@gmail.com,54234523452,and new york as location.
    [here is my table ][1]
 [1]: https://i.stack.imgur.com/M2xZS.png
what is the issue in the code 
i have try everyything from m side
if required more file will help 
how is the data is shown as 1 instead it show name and email ,location
i have try everyything from m side
if required more file will help 
how is the data is shown as 1 instead it show name and email ,location

我从m端尝试了一切     如果需要更多文件将有帮助     数据如何显示为1而不是显示名称和电子邮件,位置     我从m边尝试了一切     如果需要更多文件将有帮助     数据如何显示为1而不是显示名称和电子邮件,位置   如果需要更多文件将有帮助     数据如何显示为1而是显示名称和电子邮件地址,位置

1 个答案:

答案 0 :(得分:0)

您的插入错误,

$sql = "INSERT INTO enquiry(id,fullname,email,mobile,location,program,dateofbirth)
    VALUES ('', '".isset($_POST["fullname"])."', '".isset($_POST["email"])."','".isset($_POST["mobile"])."','".isset($_POST["location"])."','".isset($_POST["program"])."','".isset($_POST["dateofbirth"])."')";

应该是

$sql = "INSERT INTO enquiry(id,fullname,email,mobile,location,program,dateofbirth)
    VALUES ('', '".$_POST["fullname"]."', '".$_POST["email"])."','".$_POST["mobile"])."','".$_POST["location"])."','".$_POST["program"])."','".$_POST["dateofbirth"]."')";

isset —确定是否设置了一个变量,并且该变量不是NULL http://php.net/manual/en/function.isset.php

更新: 如果其自动递增https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html

,则无需传递 id

您直接在$fullname中使用$email $mobile $location $program dateofbirthINSERT,而无需致电{再次{1}}个变量