Hello. No records are added to MySQL from the html form. I tried everything, I don’t even have an empty string in the database. Until the last, I didn’t want to write here, I wanted to figure it out myself .. but I don’t have any more forces) Tell me what could be the problem? php 5.3 mysql 5.5 I know, now say, use PDO, but I'm only learning, and I want to know that, and then PDO is the code

mysql_query("INSERT INTO table_products (title, price, seo_words, seo_description, mini_description, description, mini_features, features, visible) VALUES( '".$_POST["form_title"]."', '".$_POST["form_price"]."', '".$_POST["form_seo_words"]."', '".$_POST["form_seo_description"]."', '".$_POST["txt1"]."', '".$_POST["txt2"]."', '".$_POST["txt3"]."', '".$_POST["txt4"]."', '".$chk_visible."', )",$link); $_SESSION['message'] = "<p id='form-success'>Товар успешно добавлен!</p>"; $id = mysql_insert_id(); 

and html code

 <form enctype="multipart/form-data" method="post"> <ul id="edit-tovar"> <li> <label>Название товара</label> <input type="text" name="form_title" /> </li> <li> <label>Цена</label> <input type="text" name="form_price" /> </li> <li> <label>Ключевые слова</label> <input type="text" name="form_seo_words" /> </li> <li> <label>Краткое описание</label> <textarea name="form_seo_description"></textarea> </li> </ul> <label class="stylelabel" >Основная картинка</label> <div id="baseimg-upload"> <input type="hidden" name="MAX_FILE_SIZE" value="5000000"/> <input type="file" name="upload_image" /> </div> <h3 class="h3click" >Краткое описание товара</h3> <div class="div-editor1" > <textarea id="editor1" name="txt1" cols="100" rows="20"></textarea> <script type="text/javascript"> var ckeditor1 = CKEDITOR.replace( "editor1" ); AjexFileManager.init({ returnTo: "ckeditor", editor: ckeditor1 }); </script> </div> <h3 class="h3click" >Описание товара</h3> <div class="div-editor2" > <textarea id="editor2" name="txt2" cols="100" rows="20"></textarea> <script type="text/javascript"> var ckeditor1 = CKEDITOR.replace( "editor2" ); AjexFileManager.init({ returnTo: "ckeditor", editor: ckeditor1 }); </script> </div> <h3 class="h3click" >Краткие характеристики</h3> <div class="div-editor3" > <textarea id="editor3" name="txt3" cols="100" rows="20"></textarea> <script type="text/javascript"> var ckeditor1 = CKEDITOR.replace( "editor3" ); AjexFileManager.init({ returnTo: "ckeditor", editor: ckeditor1 }); </script> </div> <h3 class="h3click" >Характеристики</h3> <div class="div-editor4" > <textarea id="editor4" name="txt4" cols="100" rows="20"></textarea> <script type="text/javascript"> var ckeditor1 = CKEDITOR.replace( "editor4" ); AjexFileManager.init({ returnTo: "ckeditor", editor: ckeditor1 }); </script> </div> <label class="stylelabel" >Галлерея картинок</label> <div id="objects" > <div id="addimage1" class="addimage"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"/> <input type="file" name="galleryimg[]" /> </div> </div> <p id="add-input" >Добавить</p> <h3 class="h3title" >Настройки товара</h3> <ul id="chkbox"> <li><input type="checkbox" name="chk_visible" id="chk_visible" /><label for="chk_visible" >Показывать товар</label></li> </ul> <p align="right" ><input type="submit" id="submit_form" name="submit_add" value="Добавить товар"/></p> </form> 
  • and what does mysql_query () return? mysql_query() возвращает TRUE в случае успеха и FALSE в случае ошибки. php.net/manual/ru/function.mysql-query.php - Jean-Claude
  • mysql_last_error or something like that try to call and see what returns. - ilyaplot

2 answers 2

Where '".$chk_visible."', Remove the comma, the request is waiting for another field, and you have already written everything.

    You have an error request.

    The string '". $ Chk_visible."' Contains an extra comma at the end. Correct the request to:

     mysql_query("INSERT INTO table_products (title, price, seo_words, seo_description, mini_description, description, mini_features, features, visible) VALUES( '".$_POST["form_title"]."', '".$_POST["form_price"]."', '".$_POST["form_seo_words"]."', '".$_POST["form_seo_description"]."', '".$_POST["txt1"]."', '".$_POST["txt2"]."', '".$_POST["txt3"]."', '".$_POST["txt4"]."', '".$chk_visible."' )",$link);