Mysql Server中的数据插入错误

时间:2014-03-23 20:15:56

标签: php html mysql sql xampp

我希望使用PHP将数据插入到mysql中。我正在编写脚本HTML,PHP和我创建的Mysql数据库。我不明白数据不发送mysql服务器。这是HTML和PHP代码:

<?php
if (isset($_POST['submit'])){
$con = mysql_connect("localhost","root","");
if(!$con){
die("Can not connect: " . mysql_error());
}
//Database Connection.

 mysql_select_db("learnarabic",$con);

 $sql = "INSERT INTO     article(ArticleDate,ArticleAuthor,ArticleSubject,ArticleSource,ArticleLevel,ArticleTitleEnglish,ArticleTitleArabic,ArticleFree,ArticleEnglish,ArticleTranslationEnglish,ArticleArabic,ArticleVowels,ArticleTransliteration,ArticleAudio) 
VALUES
('$_POST['ArticleDate']',
'$_POST['ArticleAuthor']',
'$_POST['ArticleSubject']',
'$_POST['ArticleSource']',
'$_POST['ArticleLevel']',
'$_POST['ArticleTitleEnglish']',
'$_POST['ArticleTitleArabic']',
'$_POST['ArticleFree']',
'$_POST['ArticleEnglish']',
'$_POST['ArticleTranslationEnglish']',
'$_POST['ArticleVowels']',
'$_POST['ArticleTransliteration']',
'$_POST['ArticleAudio']',
'$_POST['ArticleArabic']')";//Insert data into Mysql.


  mysql_query($sql,$con);

  mysql_close($con);//Connection Close.

 }  
 ?>

这是SQL数据库代码:

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";



            --
-- Database: `learnarabic`
            --

            -- --------------------------------------------------------

            --
            -- Table structure for table `article`
            --

            CREATE TABLE IF NOT EXISTS `article` (
              `articleid` int(250) NOT NULL AUTO_INCREMENT,
              `ArticleDate` date NOT NULL,
              `ArticleAuthor` varchar(250) NOT NULL,
              `ArticleSubject` varchar(250) NOT NULL,
              `ArticleSource` varchar(250) NOT NULL,
              `ArticleLevel` varchar(250) NOT NULL,
              `ArticleTitleEnglish` varchar(250) NOT NULL,
              `ArticleTitleArabic` varchar(250) NOT NULL,
              `ArticleFree` varchar(250) NOT NULL,
              `ArticleEnglish` longtext NOT NULL,
              `ArticleTranslationEnglish` longtext NOT NULL,
              `ArticleArabic` longtext NOT NULL,
              `ArticleVowels` longtext NOT NULL,
              `ArticleTransliteration` longtext NOT NULL,
              `ArticleAudio` blob NOT NULL,
              PRIMARY KEY (`articleid`)
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

我需要一个解决方案。

1 个答案:

答案 0 :(得分:0)

尝试从$con函数中移除mysql_query()变量,例如mysql_query($sql);也为$_POST内的任何文字添加单引号,例如$_POST['something']