简体   繁体   中英

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).

I am using PHP 4.4.9 and 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 ! 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!

可能未设置$ _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. the 100% reliable method is

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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