dongza5150 2015-04-06 19:28
浏览 35
已采纳

使用表单中的数据填充数据库

I want to fill all the fields in my database by getting the ones inputted on my form but it won't fill my database.

I don't know what's wrong with it:

    <?php

    $handle = mysql_connect("", "root" , "");       
    return mysql_select_db("bonggarden", $handle);  

    $SQL = "INSERT INTO table1(fname,femail,fphone,fmsg) 
       values('".$_POST['name']."','".$_POST['email']."','".$_POST['number']."','".$_PO  ST['message']."')";

mysql_query($SQL);

?>  

here is my form

    <form id="main-contact-form" accept-charset="utf-8" class="" method="post" >
                <div class="col-sm-5 col-sm-offset-1">
                    <div class="form-group">
                        <label>Name *</label>
                        <input type="text" name="name" id="name" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Email *</label>
                        <input type="email" name="email" id="email" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Phone *</label>
                        <input type="text" name="number" id="number" class="form-control">
                    </div>

                </div>
                <div class="col-sm-5">

                    <div class="form-group">
                        <label>Message *</label>
                        <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
                    </div>                        
                    <div class="form-group">
                        <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
                    </div>
                </div>
            </form> 
  • 写回答

3条回答 默认 最新

  • duanheyi7147 2015-04-06 19:37
    关注
    <?php
    
    
        $fname = $_POST['name'];
        $femail = $_POST['email'];
        $fphone = $_POST['number'];
        $fmsg = $_POST['message'];
    
    
        $handle = mysql_connect("localhost", "root" , "");       
        mysql_select_db("bonggarden", $handle);  
    
        $SQL = "INSERT INTO table1(fname,femail,fphone,fmsg) values('$fname','$femail','$fphone','$fmsg')";
        mysql_query($SQL);
    
    ?>  
    

    // if it still not working echo the variable $fname, $femail, $fphone, $fmsg check value is proparly getting in veriable or not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测