2016-11-27 22 views
-1

私にはわからないので、何が問題なのかを示すエラーコードはありますか?mysql dbに挿入できません

私のコードを見て1時間以上を無駄にしていますが、何も見つかりませんでした。

誰かが私のコードを見たい場合は、それはここにある:

<?php 
error_reporting(E_ALL); 
ini_set("display_errors", 1); 
require_once $_SERVER['DOCUMENT_ROOT'].'/core/init.php'; 
include 'includes/head.php';  
include 'includes/nav.php'; 

if(isset($_GET["add"])){ 

$brandQuery=$con->query("SELECT * FROM brand ORDER BY brand"); 
$parentQuery=$con->query("SELECT * FROM categories WHERE parent=0 ORDER BY category"); 

if ($_POST) { 
    $errors=array(); 

    $title=sanitize($_POST["title"]); 
    $brand=sanitize($_POST["brand"]); 
    $categories=sanitize($_POST["child"]); 
    $price=sanitize($_POST["price"]); 
    $list_price=sanitize($_POST["list_price"]); 
    $sizes=sanitize($_POST["sizes"]); 
    $description=sanitize($_POST["description"]); 

    if (!empty($_POST["sizes"])) { 
     $sizeString=sanitize($_POST["sizes"]); 
     $sizeString=rtrim($sizeString,','); 
     $sizeArray=explode(',', $sizeString); 
     $sArray=array(); 
     $qArray=array(); 
     foreach ($sizeArray as $ss) { 
      $s=explode(":",$ss); 
      $sArray[].=$s[0]; 
      $qArray[].=$s[1]; 
     }  
    }else{ 
     $sizeArray=array(); 
    } 
     $required=array("title","price","brand","child","sizes"); 
     foreach ($required as $field) { 
      if ($_POST[$field]== '') { 
       $errors[].="All fields with sterretje moet geuld worden"; 
       break; 

      } 
     } 
     if (!empty($_FILES)) { 
       var_dump($_FILES); 
       $photo=$_FILES["photo"]; 
       $name=$photo["name"]; 
       $nameArray=explode(".",$name); 
       $fileName=$nameArray[0]; 
       $fileExt=$nameArray[1]; 
       $mime=explode("/",$photo["type"]); 
       $mimeType=$mime[0]; 
       $mimeExt=$mime[1]; 
       $tmpLoc=$photo["tmp_name"]; 
       $fileSize=$photo["size"]; 
       $allowed=array("png","jpg","jpeg","gif"); 
       $uploadName=md5(microtime()).".".$fileExt; 
       $uploadPath=BASEURL."images/products/".$uploadName; 
       $dbPath="/images/products/".$uploadName; 

       if (!in_array($fileExt, $allowed)) { 
        $errors[].="File must have an png,jpg,jpeg or gif extension"; 
       } 
       if ($fileSize>15000000) { 
        $errors[].="File is bigger than 15mb"; 

       } 
       if ($mimeExt!=$fileExt) { 
        $errors[].="LOLOLOLOL gedraaag"; 
       } 
     if ($mimeType!="image") { 
      $errors[].="File must be image";   
        }   

     if (!empty($errors)) { 
      echo display_errors($errors); 
     }else{ 
       move_uploaded_file($tmpLoc, $uploadPath); 
       $insert=" 
       INSERT INTO products(`title`,`price`,`list_price`,`brand`,`categories`,`image`,`sizes`,`description`) VALUES 
           ('$title''$price''$list_price''$brand''$categories''$dbPath''$sizes''$description') 
       "; 
       if($con->query($insert)){ 
        header("Location: products.php"); 
       } 


     } 
    } 
} 

?> 


<h2 class="text-center">Add Product</h2><hr> 

<div class="form-group col-md-3"> 
    <label for="title">Title*:</label> 
    <input class="form-control" type="text" name="title" id="title" value="<?=((isset($_POST['title']))?sanitize($_POST['title']):'');?>"> 
</div> 
<div class="form-group col-md-3"> 
    <label for="brand">Brand*:</label> 
    <select class="form-control" id="brand" name="brand"> 
     <option value=""<?=((isset($_POST["brand"])&&$_POST["brand"]=="")?' selected':'');?>></option> 
     <?php while($brand=mysqli_fetch_assoc($brandQuery)): ?> 
      <option value="<?=$brand['id']?>" <?=((isset($_POST["brand"])&&$_POST["brand"]==$brand["id"])?' selected':'');?>><?=$brand['brand']?></option> 
     <?php endwhile; ?> 
    </select> 
</div> 
<div class="form-group col-md-3"> 
    <label for="parent">Parent*:</label> 
    <select class="form-control" name="parent" id="parent"> 
     <option value=""<?=((isset($_POST["parent"])&&$_POST["parent"]=="")?' selected':'');?>></option> 
     <?php while($parent=mysqli_fetch_assoc($parentQuery)):?> 
      <option value="<?=$parent['id']?>"<?=((isset($_POST["parent"]) && $_POST["parent"]==$parent["id"])?' selected':'');?>><?=$parent["category"]?></option>     
     <?php endwhile; ?>     
    </select> 
</div> 
<div class="form-group col-md-3"> 
    <label for="child">Child Category*:</label> 
    <select class="form-control" name="child" id="child">     
    </select> 
</div> 
<div class="form-group col-md-3"> 
    <label for="price">Price*:</label> 
    <input class="form-control" type="text" name="price" id="price" value="<?=((isset($_POST['price']))?sanitize($_POST['price']):'')?>"> 
</div> 
<div class="form-group col-md-3"> 
    <label for="list_price">List Price*:</label> 
    <input class="form-control" type="text" name="list_price" id="list_price" value="<?=((isset($_POST['list_price']))?sanitize($_POST['list_price']):'')?>"> 
</div> 
<div class="form-group col-md-3" > 
    <label>Quantity and Sizes*:</label> 
    <button class="btn btn-default form-control" onclick="jQuery('#sizesModal').modal('toggle');return false;" >Quantity & Sizes</button> 
</div> 
<div class="form-group col-md-3"> 
<label for="sizes">Sizes & Quantity Preview</label> 
<input class="form-control" type="text" name="sizes" id="sizes" value=" <?=((isset($_POST['sizes']))?$_POST['sizes']:'');?>" readonly> 
</div> 
<div class="form-group col-md-6" > 
    <label for="photo">Product Photo:</label> 
    <input type="file" name="photo" id="photo" class="form-control"> 
</div> 
<div class="form-group col-md-6"> 
    <label for="description">Description:</label> 
    <textarea class="form-control" name="description" id="description" rows=6> 
     <?=((isset($_POST['description']))?sanitize($_POST["description"]):'')?> 
    </textarea> 
</div> 
<div class="form-group pull-right"> 
    <input type="submit" value="Add Product" class="btn btn-success pull right"> 
</div><div class="clearfix"></div> 

</form> 

は私が問題にいただきました!見ることができる誤差関数はありますか?助けてください。

+0

「あまり明白でない」MySQL挿入の問題の一般的な原因は、「VARCHAR」フィールドにある特定のUnicode文字です。サーバー/テーブルの照合順序によっては、一部のサーバーは機能しない場合があります。間違いなくあなたの文字列の内容をチェックしてください。 –

+0

私は確認できませんでした – Fenerli

答えて

1

挿入クエリにエラーがあります。次

INSERT INTO products(`title`,`price`,`list_price`,`brand`,`categories`,`image`,`sizes`,`description`) VALUES 
           ('$title','$price','$list_price','$brand','$categories','$dbPath','$sizes','$description') 

をチェックこれは、既存のクエリです:

$insert="INSERT INTO products(`title`,`price`,`list_price`,`brand`,`categories`,`image`,`sizes`,`description`) VALUES 
          ('$title''$price''$list_price''$brand''$categories''$dbPath''$sizes''$description')"; 

お知らせカンマの自分の価値観の間の欠如。

+0

これは私のdbである何か問題が表示されませんhttps://i.gyazo.com/9f78028396bb83aa90beae36c664d804.png – Fenerli

+0

私は変数間の任意のカンマ(、)が表示されていません。それは私が言っていることです。 – reza

関連する問題