0

页面上的输出很好,没有错误或警告。它似乎应该将值插入数据库,但它没有。var_dump($result) 结果为“布尔假”。当我从命令行插入查询时,它可以工作。

功能:

    function handlePostForm(){
        date_default_timezone_set('UTC');
    if($_SERVER["REQUEST_METHOD"] == "POST"){
    if(isset($_POST['formSumbit']) && !empty($_POST['newheader']) && !empty($_POST['newpost']))
    {
       $varHeader = $_POST['newheader'];
       $varContent = $_POST['newpost'];
       $varDate = date('Y-m-d'); 
       $order ="INSERT INTO posts (header,content,post_date) VALUES      ('$varHeader','$varContent','$varDate')";
        $result = mysql_query($order);

    }

    else 
    echo "error";
    }
    }

除了调用函数的 html 表单:

<?php include('post_func.php'); ?>
<title>new post</title>
</head>
    <body dir="rtl">
    <h1>new post</h1>
    <form method='post' action="<?php $_SERVER["PHP_SELF"]?>">
    header:
    <input type="text" name="newheader" maxlength="100" style="width:500px;">
    post:
    <textarea  <input type="text" name="newpost" maxlength="100" style="width:500px;  height:500px;"/></textarea>

    <input type="submit" name="formSumbit" value="sumbit" />
    </form>

    <?php

    handlePostForm();

    ?>
4

2 回答 2

0

要获取详细信息错误,您可以尝试在 mysql_query() 函数中使用连接处理程序并使用 mysql_insert_id 来确定您的插入。还要确保在 mysql_connection 之后使用 mysql_select_db() 函数来选择数据库。

以下将是应用上述内容后的代码:

 function handlePostForm(){
 global $conn;//YOur connection
    date_default_timezone_set('UTC');
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST['formSumbit']) && !empty($_POST['newheader']) && !empty($_POST['newpost']))
{
   $varHeader = $_POST['newheader'];
   $varContent = $_POST['newpost'];
   $varDate = date('Y-m-d'); 
   $order ="INSERT INTO posts (header,content,post_date) VALUES      ('$varHeader','$varContent','$varDate')";
    $result = mysql_query($order ,$conn);

}

else 
echo "error";
}
}
于 2013-03-30T16:07:45.677 回答
0
if($_SERVER["REQUEST_METHOD"] == "POST"){
mysql_select_db("application", $con);
    mysql_query("INSERT INTO    program_info(prog_title,location,count,p_date,p_start,p_end,advisor_name,advisor_email,advisor_phone,stud1_name,stud1_email,stud1_phone,stud2_name,st
ud2_email,stud2_phone,program)
    VALUES ('$_POST[event_title]','$_POST[event_location]','$_POST[estimated_count]','','$_POST[event_starttime]','$_POST[event_endtime]','$_POST[advisor]','$_POST[advisor_email]','$_POST[phone]','$_POST[student1]','$_POST[student1_email]','$_POST[studentphone1]','$_POST[student2]','$_POST[student2_email]','$_POST[studentphone2]','$_POST[program])");
    $temp=$_POST['event_date'];
    echo $temp;
}else`
{ echo "error";
}
于 2013-10-08T18:04:24.840 回答