文件不保存在数据库中

时间:2012-11-07 11:51:27

标签: php

我正在做一个小项目,现在面对保存问题。当我在文本编辑器上输入内容时,当我单击“保存”按钮(用于保存在数据库中)时,它什么都不回复。

这里是流程代码:

case "Publish":
    $fileName=$_FILES["image"]["name"];

        if($fileName)
        {
            $filePath="images/news_img/".$fileName;
            if(file_exists($filePath))
            {
                $a=gmdate("Yzhis");
                move_uploaded_file($_FILES["image"]["tmp_name"], "images/news_img/".$a.$_FILES["image"]["name"]);
                $fileName=$a.$_FILES["image"]["name"];

            }
            else
            {
                move_uploaded_file($_FILES["image"]["tmp_name"], "images/news_img/".$_FILES["image"]["name"]);

            }
        }
        if($arttitle=="" || $date=="" || $category=="" || $status=="" )
        {
            $_SESSION['error_msg']="You Must Fill All The Required fileds";
            $go="add_articles.php";
        }
        else
        {
        /*for username check*/
            $checksql=mysql_query("select * from articles where arttitle='$arttitle'");
            $checkdata=mysql_fetch_array($checksql);

            if($checkdata['arttitle']!=$arttitle)
            {
                $inssql=mysql_query("INSERT INTO articles VALUES(NULL,'$arttitle','$date','$category','$status','$fileName','$articale',0)");
            }
            else
            {
                $_SESSION['username_msg']="Articale Name Already Exists.";
            }
        }
        $go="add_articles.php";

    break;

    case"Edit":
    $updatesql=mysql_query("UPDATE articles SET 
arttitle='$arttitle',date='$date',category='$category',status='$status',articale='$articale' where aid = '$hiddenid'");
    $_SESSION['success_msg']="Update Successful!";
        $go="add_articles.php";
    break;

1 个答案:

答案 0 :(得分:0)

更改

$checkdata=mysql_fetch_array($checksql);

$checkdata = mysql_fetch_array($checksql,MYSQL_BOTH);

您正在使用字段名称进行比较,因此您必须更改提取数组

$checksql=mysql_query("select * from articles where arttitle='".$arttitle."'"); 


$inssql=mysql_query("INSERT INTO articles VALUES(NULL,'".$arttitle."','".$date."','".$category."','".$status."','".$fileName."','".$articale."',0)");