doushi8599 2017-03-16 16:50
浏览 40
已采纳

从PHP / HTML表单更新SQL

Im trying to update a table with info from a form. I have one that works in a different file for table in the same database. My version just will not enter data into the table. I feel like I've edited/copied it correctly, I'm very much a noob and feel like there may be an obvious answer but i just cant see it. I've check similar questions but no luck.

<?php include "connect.php";?>

<!DOCTYPE html>
<html lang="en">


<head>
    <meta http-equiv="Content-Type" content= "text/html; charset=UTF-8"/> 
    <title>Blooming Flowers - Registration</title>
    <link rel="stylesheet" href="css/style.css" type="text/css">

</head>


<?php include "header.php"; ?>
<?php include "form.php"; ?>
<body>



        <?php include "processform.php" ; ?>

        </td>

        </tr></table>


    <?php include "footer.php"; ?>





</body>

I can narrow the problem down to either my form.php file or processform.php file but not sure why they dont work

form.php

        <td>

        <div class="form">
        <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <fieldset>

                <h3>Personal Details</h3><br>

                <label>Title:

                    <select name="titles">
                        <option value="mr">Mr.</option>
                        <option value="mrs">Mrs.</option>
                        <option value="ms">Ms.</option>
                        <option value="Dr">Dr.</option>
                    </select></label>

                    <p>
                        <label for="firstName"> First Name:</label>
                        <input type="text" name="user_first" id="user_first" size="40" maxlength="60" required/>
                    </p>

                    <p>
                        <label for="lastName">Last Name:</label>
                        <input type="text" name="user_last" id="user_last" size="40" maxlength="60" required/>
                    </p>



                    <p>
                        <label for="password"> Password:</label>
                        <input type="password" name="user_pass" id="user_pass" size="40" maxlength="60" required/>
                    </p>

                    <p>
                        <label for="confirmPass"> Confirm Password:</label>
                        <input type="password" name="" id="" size="40" maxlength="60" required/>
                    </p>

            </fieldset><!--name fieldset closed-->

            <fieldset>

                <h3> Delivery Details</h3><br>

                    <p>
                        <label for="streetAddress"> Street:</label>
                        <input type="text" name="user_street" id="user_street" size="40" maxlength="60" required/>
                    </p>

                    <p>
                        <label for="city"> City:</label>
                        <input type="text" name="user_city" id="user_city" size="40" maxlength="60" required/>
                    </p>

                    <p>
                        <label for="postcode"> Postcode:</label>
                        <input type="text" name="user_post" id="user_post" size="40" maxlength="60" required/>
                    </p>

                    <p>
                        <label for="email"> E-Mail:</label>
                        <input type="email" name="user_email" id="user_email" size="40" maxlength="60" required/>
                    </p>

                    <p>
                        <label for="confirmEmail"> Confirm E-Mail:</label>
                        <input type="email" name="" id="" size="40" maxlength="60" required/>
                    </p>


            </fieldset><!-- fieldset closed-->



            <br><input class="link-button-pagemenu" name="submit" type="submit" value="Register">

        </form><!--form closed-->

    </div><!-- form div closed-->

processform.php

<?php


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

  $user_first=      '';  
  $user_last =      '';
  $user_pass =      '';
  $user_street =    '';
  $user_city =      '';
  $user_post =      '';
  $user_email =     '';

  if (!empty($_POST['user_first'])){
  $user_first = $_POST['user_first'];
  }
  if (!empty($_POST['user_last'])){
    $user_last = $_POST['user_last'];
  }

  if (!empty($_POST['user_pass'])){
$user_pass = $_POST['user_pass'];
  }

  if (!empty($_POST['user_street'])){
   $user_street = $_POST['user_street'];
  }

   if (!empty($_POST['user_city'])){
$user_city = $_POST['user_city'];
  }

   if (!empty($_POST['post'])){
$user_post = $_POST['user_post'];
  }

   if (!empty($_POST['user_email'])){
$user_email = $_POST['user_email'];
  }

  $query = "insert into flower (user_first, user_last, user_pass, user_street, user_city, user_post, user_email) 
values('$user_first', '$user_last',     '$user_pass', '$user_street', '$user_city', '$user_post', '$user_email')";

  mysqli_query($connect, $query);
}


?>

my database table is called flower and has userID (PK), user_first, user_last, user_pass, user_street, user_city, user_post, user_email,

  • 写回答

1条回答 默认 最新

  • dongpiao1983 2017-03-16 16:57
    关注

    You are basically not posting your data to your processform.php file. Using <?php echo $_SERVER['PHP_SELF']; ?> in your action, will make the page post to itself, which mean, it's gonna be posted to your form.php file, not processform.php.

    Change your form action to use the processform.php and then you should hit your query and get data into your database.

    Maybe you can go here and also read a bit on global php variables:

    Hope this help you :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?