简体   繁体   English

mysql插入成功,但未添加任何内容

[英]mysql insert success but nothing is added

look at this code 看这段代码

<?
require_once("conn.php");
require_once("includes.php");
require_once("access.php");

if(isset($_POST[s1]))
{
    //manage files
    if(!empty($_FILES[images]))
    {
        while(list($key,$value) = each($_FILES[images][name]))
        {
            if(!empty($value))
            {
                $NewImageName = $t."_".$value;
                copy($_FILES[images][tmp_name][$key], "images/".$NewImageName);

                $MyImages[] = $NewImageName;
            }
        }

        if(!empty($MyImages))
        {
            $ImageStr = implode("|", $MyImages);
        }
    }

    $q1 = "insert into class_catalog set 
                                MemberID = '$_SESSION[MemberID]',
                                CategoryID = '$_POST[CategoryID]',
                                Description = '$_POST[Description]',
                                images = '$ImageStr',
                                DatePosted = '$t',
                                DateExp = '$_SESSION[AccountExpDate]',
                                FeaturedStatus = '$_POST[sp]' ";
//echo $q1;
    mysql_query($q1) or die(mysql_error());

}

//get the posted offers
$q1 = "select count(*) from class_catalog where MemberID = '$_SESSION[MemberID]' ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);



header("location:AddAsset.php");

exit();

?>

The mySql insert function isn't adding anything also it return success to me , I've tried using INSERT ... Values but what it done was overwtiting existing value ( ie make 1 entry and overwties it everytime). mySql insert函数没有添加任何东西,它也向我返回了成功,我尝试使用INSERT ...值,但是这样做是夸大了现有的值(即每次输入1并覆盖它)。

I am using PHP 4.4.9 and MySql 4 我正在使用PHP 4.4.9和MySql 4

I tried to add from Phpmyadmin and it is working also it was working after installation but after i quit the browser and made a new account to test it it is not working but the old ones is working ! 我尝试从Phpmyadmin添加文件,并且它在安装后也可以正常工作,但是我退出浏览器并注册了一个新帐户进行测试后,它不起作用,但是旧的却可以工作! you can see it here http://bemidjiclassifieds.com/ try to login with usr:openbook pass:mohamed24 and you can see it will be working but any new account won't work! 您可以在这里看到它http://bemidjiclassifieds.com/尝试使用usr:openbook pass:mohamed24登录,您可以看到它可以使用,但是任何新帐户都无法使用!

可能未设置$ _POST [s1],或者您要插入的数据库与正在观看的数据库不同。

if(isset($_POST[s1]))

should probably be 应该是

if(isset($_POST['s1']))

(note the quotes). (请注意引号)。 Also, it's best to NOT depend on a field being present in the submitted data to check if you're doing a POSt. 另外,最好不要依赖于提交的数据中存在的字段来检查您是否正在执行POSt。 the 100% reliable method is 100%可靠的方法是

if ($_SERVER['REQUEST_METHOD'] == 'POST') { ... }

As well, you're not checking if the file uploads succeeded. 同样,您也不会检查文件上传是否成功。 Each file should be checked like this: 每个文件应按以下方式检查:

foreach($_FILES['images']['name'] as $key => $name) {
   if ($_FILES['images']['error'][$key] !== UPLOAD_ERR_OK) {
       echo "File #$key failed to upload, error code {$_FILES['images']['error'][$key]}";
   }
   ...
}

Don't use copy() to move uploaded files. 不要使用copy()移动上载的文件。 There's a move_uploaded_files() function for that, which does some extra sanity checking to make sure nothing's tampered with the file between the time the upload finished and your script tries to move it. 为此,有一个move_uploaded_files()函数,该函数会进行一些额外的检查,以确保在上传完成和脚本尝试移动文件之间没有任何文件被篡改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM