dongshengheng1013 2011-12-19 20:32
浏览 40
已采纳

发送到DB功能不执行

This function gets the date from the user:

function getCCGraduationDate () {
        ?>
        <form method="post" action="processor.php">
        Graduation Date: <input type="text" name="CCgraduationdate"><br>
        <input type="submit">
        <?php
    }

This function sends the value to a DB and is called on the processor.php page:

function sendCCGraduationDate () {
    $con = mysql_connect("localhost","root","XXXXXX");
    if (!$con)
        {
    die('Could not connect: ' . mysql_error());
        }
        mysql_select_db("user", $con);
        $grad = mysql_real_escape_string($_POST['CCGraduationDate'], $con);
        $sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=$this->user_id";
        mysql_query( $sql , $con );

        mysql_close($con);

    }

For some reason the value isn't populating in the database. I had tested similar functions last night and they worked, not sure what I'm missing here.

  • 写回答

2条回答 默认 最新

  • duanlu0075 2011-12-19 21:07
    关注

    Please check this:

    FORM CODE:

    <input type="text" name="CCgraduationdate"><br>
    

    PHP CODE:

    $grad = mysql_real_escape_string($_POST['CCGraduationDate'], $con);
    

    Your CCgraduationdate in your form is unequal to CCGraduationDate in your php code

    If you're not getting an error like:

    Notice:  Undefined index: CCGraduationDate /* blah blah blah */
    

    Then you can try adding at the top of your PHP code:

    error_reporting(E_ALL);
    

    And then see if an error comes out.

    Of course, that's after changing your $sql variable's data to:

    $sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=" . $this->user_id;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?