数据库和前端没有获取数据

时间:2016-08-27 05:32:36

标签: php

这是我从表单插入数据的代码。         我可以直接从数据库添加数据,但当我用html格式插入数据时,我没有得到任何错误。它继续上传     成功。但可以看到任何数据在前端添加,也可以在     数据库。

    <?php
        session_start();
        include('db.php');
        $con = mysql_connect("localhost","root","");
        $db=mysql_select_db("jobs");
        $image = $_FILES['image']['name'];
        $arr=explode(".", $image);
        $arr_image=$arr[0].rand();
        $image=$arr_image.".".$arr[1];
        $fname=$_POST['fname'];
        $mname=$_POST['mname'];
        $sname=$_POST['sname'];
        $country=$_POST['country'];
        $city=$_POST['city'];
        $add=$_POST['add'];
        $mob=$_POST['mob'];
        $email=$_POST['email'];
        $website=$_POST['website'];
        $bio=$_POST['bio'];
        $jobt=$_POST['jobt'];
        $dfrom=$_POST['dfrom'];
        $dto=$_POST['dto'];
        $sd=$_POST['sd'];
        $schooln=$_POST['schooln'];
        $degree=$_POST['degree'];
        $shortd=$_POST['shortd'];
        $cv = $_FILES['cv']['name'];
        $file_tmp1 =$_FILES['image']['tmp_name'];
        $file_tmp2 =$_FILES['cv']['tmp_name'];
        move_uploaded_file($file_tmp1,"uploads/".$image); 
        move_uploaded_file($file_tmp2,"uploads/".$cv); 



        $sql="INSERT INTO  `jobs`.`resume` (`id` ,`image` ,`fname` ,`mname` ,`sname` ,`country` ,`city` ,`add` ,`mob` ,`email`
,`website` ,`bio` ,`jobt` ,`dfrom` ,`dto` ,`sd` ,`schooln` ,`degree`
,`shortd` ,`cv`)
        VALUES ( '$image','$fname',  '$mname',  '$sname', '$country', '$city',  '$add',  '$mob',  '$email',  '$website', 
'$bio',  '$jobt',  '$dfrom',  '$dto',  '$sd',  '$schooln', 
'$degree',  '$shortd','$cv') ";




        //include('candidates.php');
        //print_r($sql); die;
        if ($sql) {



        mysql_query($sql);
        echo" resume uploaded successfully";
        mysql_close($con);
        }
        ?>

2 个答案:

答案 0 :(得分:0)

试试这个,看看错误是什么

$result=mysql_query($sql);
if(!$result)
{
   echo mysql_error();
}

答案 1 :(得分:0)

issue is:        字段列表中的给定id列,但不为该id列赋值。

id列是auto_increment mean。 像这样删除id列名称

        $sql="INSERT INTO  `jobs`.`resume` (`image` ,`fname` ,`mname` ,`sname` ,`country` ,`city` ,`add` ,`mob` ,`email`
    ,`website` ,`bio` ,`jobt` ,`dfrom` ,`dto` ,`sd` ,`schooln` ,`degree`
    ,`shortd` ,`cv`)
            VALUES ( '$image','$fname',  '$mname',  '$sname', '$country', '$city',  '$add',  '$mob',  '$email',  '$website', 
    '$bio',  '$jobt',  '$dfrom',  '$dto',  '$sd',  '$schooln', 
    '$degree',  '$shortd','$cv') ";