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 :)

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

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题