我有一张上传excel文件的表格,如
<form enctype="multipart/form-data" action="http://localhost/joomla/Joomla_1.5.7/index.php?option=com_jumi&fileid=7" method="POST">
Please choose a file: <input name="file" type="file" id="file" /><br />
<input type="submit" value="Upload" />
</form>
在FIle http://localhost/joomla/Joomla_1.5.7/index.php?option=com_jumi&fileid=7
中i have retrived the uploaded file contents by
<?php echo "Name". $_FILES['file']['name'] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br />";
$string = file_get_contents( $_FILES["file"]["tmp_name"] );
foreach ( explode( "\n", $string ) as $userString )
{
$userString = trim( $userString );
echo $userString;$array = explode( ';', $userString );
$userdata = array
( 'cf_id'=>trim( $array[0] ),
'text_0'=>trim( $array[1] ),
'text_1'=>trim( $array[2] ),
'text_2'=>trim( $array[3] ),
'text_3'=>trim($array[4]),
'text_6'=>trim($array[5]),
'text_7'=>trim($array[6]),
'text_9'=>trim($array[7]),
'text_12'=>trim($array[8]));
global $db; $db=& JFactory::getDBO();
$query = 'INSERT INTO #__chronoforms_UploadAuthor VALUES ("'.$userdata['cf_id'].'","'.$userdata['text_0'].'","'.$userdata['text_1'].'","'.$userdata['text_2'].'","'.$userdata['text_3'].'","'.$userdata['text_6'].'","'.$userdata['text_7'].'","'.$userdata['text_9'].'")';
$db->Execute($query);
echo "<br>";
}
我正在尝试将内容插入到Joomla数据库中的#__chronoforms_UploadAuthor表中。它会显示任何错误但它没有插入数据库..
请帮帮我.Y内容没有插入数据库......以及如何将其插入数据库..
编辑:
我已经回应了查询,并显示为 INSERT INTO jos_chronoforms_UploadAuthor VALUES(“1”,“”Concept-paper-WSN_02.pdf“”,“”Wi-SenseScape,无线传感器网络“”,“TCS创新实验室,班加罗尔”,“”内部“”,“ “Wi-SenseScape”“,”“Harish Reddy,Vishnu,Deepika,T.Chakravarty和Balamuralidhar”,“”2008“”,“”,“”)..因为有2个双引号,所以没有插入数据库..请告诉我如何解决这个问题。
这样Query应该是这样的 INSERT INTO jos_chronoforms_UploadAuthor VALUES(“1”,“Concept-paper-WSN_02.pdf”,“Wi-SenseScape,无线传感器网络”,“TCS创新实验室,班加罗尔”,“内部”“,”“Wi-SenseScap”, “Harish Reddy,Vishnu,Deepika,T.Chakravarty和Balamuralidhar”,“2008”,“”,“”
答案 0 :(得分:2)
首先尝试找出sql查询:
echo $query;
现在复制该查询并在mysql客户端中执行,如phpmyadmin或sqlyog。如果插入了记录,那么您的代码中的其他地方就会出现错误,但如果您发现任何错误,则应尝试在查询中解决该错误。
修改强>
您需要在插入数据库的值之前使用addslashes
或mysql_real_escape_string
函数:
$query = 'INSERT INTO #__chronoforms_UploadAuthor VALUES ("'.addslashes($userdata['cf_id']).'","'.addslashes($userdata['text_0'])............and so on