记录未插入mysql数据库

时间:2015-01-22 09:08:37

标签: php

我没有收到任何错误,但数据库没有得到更新。请提供帮助。这是我的代码。

<?php
ob_start();
include("dbinc.php");
$msg = "";

if($_SESSION['usertype'] != "admin"){
    header("Location: index.php");
    exit;
}

$pagetitle = "Sync Job Details";
include("header.php");

if(isset($_POST['Submitaccount'])){

    $allowedusers = $_POST['users'];
    $accountid = trim($_POST['accountid']);
    if(!$_POST['copyperms']) $_POST['copyperms']='N';
    if(!$_POST['allusers']) $_POST['allusers']='N';
    if(!$_POST['enabled']) $_POST['enabled']='N';
    if(!$_POST['servertime']) $_POST['servertime']='N';
    if(!$_POST['delremovals']) $_POST['delremovals']='N';

    unset($_POST['Submitaccount']);
    unset($_POST['accountid']);
    unset($_POST['users']);

    // $qpart = "";
    $notmust = array("email" , "skip" , "comments" , "firstmod");

    foreach($_POST as $key=>$val){
        if(!trim($val) && !in_array($key , $notmust)) {
            $err = 1;
            $empty = "$key";
            break;
        }
        $qpart .= "`$key` = '".mysql_escape_string($val)."' , " ;
    }
    if($qpart) $qpart = substr($qpart , 0 , -2);

    if(!$err){
        $chk = mysql_num_rows(mysql_query("SELECT * from accounts WHERE name = '".mysql_escape_string($_POST['name'])."' and id <> '$accountid'"));
        if($chk >0){
            $err = 2;
        }
    }

    if(!$err){
        if(!$accountid){
            $q = "INSERT into accounts SET $qpart ";
            mysql_query($q) or die("Error inserting the record :".mysql_error()."<br>".$q);
            $accountid = mysql_insert_id();
        }else{
            $q = "UPDATE accounts SET $qpart WHERE id = '$accountid'";
            mysql_query($q) or die("Error updating the record :".mysql_error()."<br>".$q);
        }

        if($_POST['allusers']!= "Y" && is_array($allowedusers)){
            mysql_query("DELETE from accountusers WHERE accountid = '$accountid'");
            foreach($allowedusers as $userid){
                list($alljobs) = mysql_fetch_row(mysql_query("SELECT alljobs from users WHERE id= '$userid'"));
                if($alljobs != "Y") {
                    mysql_query("INSERT into accountusers SET userid = '$userid' , accountid = '$accountid'");
                }   
            }
        }else{
            mysql_query("DELETE from accountusers WHERE accountid = '$accountid'");
        }

        header("location: accountslist.php?done=1");
        exit;
    }


}

// if(isset($_GET['id'])){
//  $record = mysql_fetch_assoc(mysql_query("SELECT * from accounts WHERE id = '$_GET[id]'"));
//  foreach($record as $key=>$val) $record[$key] = stripslashes($val);
// }
if(isset($_GET['id'])){
    $record = mysql_fetch_assoc(mysql_query("SELECT * from accounts WHERE  id = '$_GET[id]'"));
    foreach($record as $key=>$val) $record[$key] = stripslashes($val);
}





// if($err ==1)
// {
//   $record = $_POST;
//   foreach($record as $key=>$val) 
//       $record[$key] = stripslashes($val); 

//   $msg ="Please fill the empty field"; 
// }
if( isset($err)  && $err == 1 )
 {  
      $record = $_POST;
      foreach($record as $key=>$val) $record[$key] = stripslashes($val);
      $msg ="Please fill the empty field";
 }

if( isset($err) && $err == 2) 
 {
    $msg = "The name has already been used.";
}

?>

1 个答案:

答案 0 :(得分:0)

我感到沮丧。如果我可以帮助你,我会的。这个论坛的人很害怕回答你,因为他们不想失去声望点,因为问题被标记为-4。我建议做更多的研究,并发布你的问题eslewhere。

相关问题