Jump to content

INSERT INTO don't work


hottern

Recommended Posts

Hello, I can't add record to my table. File loaded is ok, so it's just problem with INSERT?

   private function _postProcess() {
    $filename = $_FILES['filename']['name'];
    $uploads_dir =_PS_MODULE_DIR_.$this->name.'/'.$_FILES["filename"]["name"];
 //   var_dump($filename) ;
    if (!move_uploaded_file($_FILES['filename']['tmp_name'], $uploads_dir)) {
	   // $errors .= $this->l('File upload error.');
	    Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'pay_icon` (`icon_img`,`icon_link`,`icon_status` )
	   VALUES ("'.pSQL($filename).
		    '", "'. pSQL($_POST['alt']).'" , "1")');
    }
	    if($_FILES["filename"]["size"] > 1024*3*1024)
    {
	    echo ("Размер файла превышает три мегабайта");
	    exit;
    }
    }

 

This is my form

 

<form action="index.php" method="post" enctype="multipart/form-data">
  <fieldset>
  <legend>'.$this->l('Загрузка новой картинки').'</legend>
	    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
	    '.$this->l('Название (alt-поле)').':<br />
	    <input type="text" name="alt" value="" /><br />
	    '.$this->l('Выберите изображение').':<br />
	    <input type="file" name="filename" /><br />
  <br />
  <input type="submit" name="btnSubmit" class="button" value="'.$this->l('Загрузить').'">
 </fieldset>
    </form>

Link to comment
Share on other sites

Best thing for debuggin is to add a line in MySQL Class - just to show final query. Take the statement and put it into phpmyadmin and see whats happens ;)

 

This is the way I would do.

 

nice tip, Im also use this way to debug mysql queris :-) @hottern please let us know about your issue

Link to comment
Share on other sites

I don't know what was wrong but now it's work fine

   private function _postProcess()
   {
    $filename = $_FILES['filename']['name'];
    $file_ext = substr($filename, 1 + strrpos($filename, "."));
    $name=md5 (uniqid ());
    $file_name_new = _PS_MODULE_DIR_.$this->name.'/img/'.$name.".".strtolower($file_ext);
    if  ($file_ext == "jpg" OR $file_ext == "png" OR $file_ext == "gif"){
	    if (move_uploaded_file($_FILES['filename']['tmp_name'], $file_name_new)) {
		    Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'pay_icon` (`icon_img`,`icon_link`,`icon_status` )
			 VALUES ("'.$name.".".strtolower($file_ext).'", "'.$_POST['alt'].'" , "1")');
	    }
    }
    else {
	    echo ("Не правильный формат файла");
    }
    if($_FILES["filename"]["size"] > 1024*10*1024){
		  echo ("Размер файла превышает 10 мегабайт");
		  exit;
    }
   }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...