PHP无法将变量插入数据库

时间:2015-12-20 13:40:29

标签: php mysql post insert

问题出在INSERT INTO语句中。我试图插入$ today,$ id,$ stat_sum,$ klientas。除了$ id之外,一切都在插入。在我按下提交按钮后,一切都在插入,但是应该有$ id,它显示为NULL。我试图回显$ id,它正常显示它应该是。

    $today = date('Y-m-d G:i:s');
if( isset($_GET['pas']) )
    {
        $id = $_GET['pas'];
        $res= mysql_query("SELECT MAX(statymo_suma) FROM statymai WHERE aukciono_id = '$id'");
        $row= mysql_fetch_array($res);
        echo $id;

    }
if( isset($_POST['stat_sum']) )
    {
        echo '<input type="hidden" name="id" value="<?php echo $row[2]; ?>">';
        $stat_sum = $_POST['stat_sum'];
        $id = $_POST['id'];
        $res1= mysql_query("SELECT kliento_id FROM klientai WHERE vartotojo_vardas = '$user_check'");
        $row1 = mysql_fetch_assoc($res1);
        $klientas = $row1['kliento_id'];


        $sql = "INSERT INTO statymai (statymo_laikas,aukciono_id,statymo_suma,kliento_id) VALUES ('$today','$id','$stat_sum','$klientas')";


                     $res =mysql_query($sql)
                                            or die("Negaliu redaguoti".mysql_error());

        //echo "<meta http-equiv='refresh' content='0;url=redaguoti.php'>";


    } 

?>
<form action="pasiulymas.php" method="POST">
Statymo suma: <input type="text" name="stat_sum" value="<?php echo $row[0]; ?>"><br />
<input type="hidden" name="id" value="<?php echo $row[2]; ?>">
<input type="submit" value=" =Redaguoti "/>
</form> 

var_dump($ sql)结果:

string(123) "INSERT INTO statymai (statymo_laikas,aukciono_id,statymo_suma,kliento_id) VALUES ('2015-12-20 15:04:50','','123456','KL01')"

0 个答案:

没有答案