Unknown column '****' in 'field list' - MySQL
Формулировка задачи:
Всем привет!
При добавлении статьи, пишет: Unknown column 'Acme' in 'field list' ( после того, как отправил запрос в БД ). Там где указываю Acme - логин пользователя (никаких проверок нет).
Как я понимаю, ошибка из-за того, что не заполнено/не найдена надпись Acme в колонке? Вроде теги все закрыты, лишних запятых нет. Сама логика построена не верно?
<!-- Header (Logo. Slogan). Connect database --> <?php $base_path = $_SERVER["DOCUMENT_ROOT"]."/"; define("BASE_PATH", $base_path); require_once $base_path . 'controller/config.php'; if($_POST['submit']){ $title = mysql_real_escape_string($_POST['title']); $keywords = mysql_real_escape_string($_POST['keywords']); $description = mysql_real_escape_string($_POST['description']); $anons = mysql_real_escape_string($_POST['anons']); $category = (int)$_POST['$category']; $date = date("Y-m-d"); $author = mysql_real_escape_string($_POST['author']); $res = mysql_query("INSERT INTO `articles` SET `title`='{$title}', `keywords`='{$keywords}', `description`='{$description}', `date`='{$date}', `author`={$author}, `anons`='{$anons}', `category`='{$category}'") or die(mysql_error()); if(mysql_affected_rows() > 0){ $_SESSION['res'] = '<strong>Статья успешно добавлена!</strong>'; header("Location: add_article.php"); exit; }else{ $_SESSION['res'] = '<strong>К сожалению, что-то пошло не так. :(</strong>'; header("Location: add_article.php"); exit; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title><?php echo A_NAME ?> - Добавление статьи</title> <!-- CKEDITOR ( http://ckeditor.com ) --> <script src="ckeditor/ckeditor.js"></script> <!-- AjexFileManager --> <script src="AjexFileManager/ajex.js"></script> <!-- Favicon --> <link rel="shortcut icon" type="image/icon" href="/assets/images/favicon.ico"/> <!-- Font Awesome --> <link href="/assets/css/font-awesome.css" rel="stylesheet"> <!-- Bootstrap --> <link href="/assets/css/bootstrap.css" rel="stylesheet"> <!-- Slick slider --> <link rel="stylesheet" type="text/css" href="/assets/css/slick.css"/> <!-- Fancybox slider --> <link rel="stylesheet" href="/assets/css/jquery.fancybox.css" type="text/css" media="screen" /> <!-- Animate css --> <link rel="stylesheet" type="text/css" href="/assets/css/animate.css"/> <!-- Theme color --> <link id="switcher" href="/assets/css/theme-color/default.css" rel="stylesheet"> <!-- Main Style --> <link href="/style.css" rel="stylesheet"> <!-- Fonts --> <!-- Open Sans for body font --> <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'> <!-- Raleway for Title --> <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'> <!-- Pacifico for 404 page --> <link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <!-- BEGAIN PRELOADER --> <!-- <div id="preloader"> <div class="loader"> </div> </div> --> <!-- END PRELOADER --> <!-- SCROLL TOP BUTTON --> <a class="scrollToTop" href="#"><i class="fa fa-chevron-up"></i></a> <!-- END SCROLL TOP BUTTON --> <!-- Start menu section --> <section id="menu-area"> <nav class="navbar navbar-default main-navbar" role="navigation"> <div class="container"> <div class="navbar-header"> <!-- FOR MOBILE VIEW COLLAPSED BUTTON --> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <!-- LOGO --> <a class="navbar-brand logo" href="<?= A_URL ?>"><img src="/assets/images/logo.jpg" alt="logo"></a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul id="top-menu" class="nav navbar-nav main-nav menu-scroll"> <li><a href="<?= URL ?>">Главная</a></li> <li class="active"><a href="<?= A_URL ?>">Адмика</a></li> </ul> </div><!--/.nav-collapse --> <div class="search-area"> <form action=""> <input id="search" name="search" type="text" placeholder="What're you looking for ?"> <input id="search_submit" value="Rechercher" type="submit"> </form> </div> </div> </nav> </section> <!-- End menu section --> <!-- Start blog banner section --> <section id="blog-banner"> <img src="/assets/images/blog-banner.jpg" alt="Header Logo"> <div class="blog-overlay"> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="blog-banner-area"> <h2><?php echo A_SLOGAN;?></h2> </div> </div> </div> </div> </div> </section> <!-- End blog banner section --> <!-- /Header (Logo. Slogan). Connect database --> <!-- Start blog section --> <section id="blog"> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="blog-area"> <div class="row"> <div class="col-lg-8 col-md-7 col-sm-12"> <div class="blog-left blog-archive"> <?php echo $_SESSION['res']; unset($_SESSION['res']); ?> <form method="post"> <table> <tr> <td> Название: </td> <td> <input type="text" name="title" maxlength="255" size="50"> </td> </tr> <tr> <td> Ключевые слова: </td> <td> <input type="text" name="keywords" maxlength="255" size="50"> </td> </tr> <tr> <td> Краткое описание: </td> <td> <textarea name="anons" id="anons" cols="50" rows="5"></textarea> <script> var anons = CKEDITOR.replace('anons'); AjexFileManager.init({returnTo:'ckeditor',editor:anons}); </script> </td> </tr> <tr> <td> Описание: </td> <td> <textarea name="description" id="description" cols="50" rows="10"></textarea> <script> var description = CKEDITOR.replace('description'); AjexFileManager.init({returnTo:'ckeditor',editor:description}); </script> </td> </tr> <tr> <td> Категория: </td> <td> <select name="category"> <?php $res = mysql_query("SELECT * FROM `category`"); while ($row = mysql_fetch_assoc($res)){ echo "<option value='{$row['id']}'>{$row['name']}</option>\r\n"; } ?> </select> </td> </tr> <tr> <td> Автор: </td> <td> <input type="text" name="author" maxlength="50" size="18"> </td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Добавить"></td> </tr> </table> </form> </div> </div> <!-- right sidebar --> <?php include $base_path . A_VIEW . '/sidebar.php';?> <!-- /right sidebar --> </div> </div> </div> </div> </div> </section> <!-- End blog section --> <!--footer/LOGO/Soc.icons/Copyright--> <?php include $base_path . A_VIEW . '/footer.php' ?> <!--/footer/LOGO/Soc.icons/Copyright-->
Решение задачи: «Unknown column '****' in 'field list'»
textual
Листинг программы
INSERT INTO <имя таблицы>[(<имя столбца>,...)] {VALUES (<значение столбца>,…)}
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д