<?php
session_start();
$name=$_POST['title'];
$auther=$_POST['auther'];
$kind=$_POST['kind'];
$time=date("Y-m-d H:i:s");
$res=$_POST['res'];
$uploader=$_SESSION['name'];
/*echo $name;
echo $auther;
echo $kind;
echo $time;
echo $res;
echo $uploader;*/
$host="192.168.12.50";
$user="root";
$pwd="123456";
$db=mysql_connect($host, $user, $pwd) or die('Could not connect: ' . mysql_error());
/*if($db){
echo "1";
}else{
echo "0";
}*/
    mysql_select_db("xujun", $db);
    mysql_query("SET NAMES gb2312", $db);
$sql="insert into docu_info (name,auther,kind,creat_time,res,uploader) values ('$name','$auther','$kind','$time','$res','$uploader')";
mysql_query($sql,$db);
mysql_close($db);?>POST提交表单,注释部分都经过验证,输入的变量都有值,数据库也连接成功了,但是为什么插不进去呢?

解决方案 »

  1.   

    没有报错,表单代码:
    <form action="upload.php" method="POST" enctype="multipart/form-data" name="form1">
    使用方法:
    <p>书名:
    <input type="text" name="title"></p>
    <p>作者:
    <input type="text" name="auther"></p>
    <p>类别:
    <input type="text" name="kind"></p>
    <p>路径:
    <input type="file" name="file"></p>
    <p>说明:
    <textarea  name="res" ></textarea></p>
    <input type="submit" name="Submit" value="提交">
    <input name="scan" type="hidden" id="up" value="true">
    </form>
      

  2.   

    mysql_query("SET NAMES gb2312", $db);
    改成mysql_query("SET NAMES utf8", $db)試試。
      

  3.   

    "xujun"这个是库的名字吧!
    看看在不
      

  4.   

    mysql_query($sql,$db);
    可以这么用吗!把是这个mysql_query($sql);我无语!
      

  5.   

    饿
    试了下
    可以这样用!
    你可以把这句话先注掉试试
    mysql_query("SET NAMES gb2312", $db);
      

  6.   


    $sql="insert into docu_info (name,auther,kind,creat_time,res,uploader) values ('$name','$auther','$kind','$time','$res','$uploader')";
    mysql_query($sql,$db);
    下面加一句输出错误的代码:echo mysql_error();
      

  7.   

    输出sql语句,还有你的变量的数据类型!是不是要加双引号!!!!!!!!!!!
      

  8.   

    <form action="upload.php" method="POST" enctype="multipart/form-data" name="form1">修改为:
    <form action="upload.php" method="POST" name="form1">
    form设置了enctype="multipart/form-data" 属性后,就是2进制传输数据了 form里面的input的值传过去的不是以2进制的方式,所以$_post就得不到值了。
      

  9.   

    给你的函数,加在session_start();下面:
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
    if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }
    然后将你的原句$sql="insert into docu_info name,auther,kind,creat_time,res,uploader) values ('$name','$auther','$kind','$time','$res','$uploader')";
    改为如下:
    $sql = sprintf("insert into docu_info (name,auther,kind,creat_time,res,uploader) values (%s, %s, %s, %s, %s, %s,%s)",
    GetSQLValueString($name, "text"),
    GetSQLValueString($auther, "text"),
    GetSQLValueString($kind, "text"),
    GetSQLValueString($time, "date"),
    GetSQLValueString($res, "text"),
    GetSQLValueString($uploader, "text"));
    请一定要核对一下类型是否与数据库中字段一致.
      

  10.   

     应该是你的sql语句错了,你可以把SQl语句打印出来,自己手动执行!看是否有错!或者用上面的几楼所说的试试!这种错误,应该一步一步的检查!细心些!加油!