<h1>Length required</h1>在向服务器提交帖子字符串时,我一直收到错误.
$cookie = "Secret cookie data here";
$searchData = array(
'__EVENTTARGET' => 'ctl00$main$btn',
'ctl00$main$tbMNr' => $_GET['smth'],
'ctl00$main$tbMb' => $_GET['smthElse'],
'__VIEWSTATE' => 'smthElseHere'
);
// Commenting this out, as suggested by user lonesomeday
//foreach ($searchData as &$elem) // This should not be necessary
// $elem = urlencode($elem);
// create a new cURL resource
$fields = http_build_query($searchData); // Assuming it's an array
if ($ch = curl_init("http://mysite.com"))
{
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); …Run Code Online (Sandbox Code Playgroud) 为了进行年度库存计数,我们一直在小型公司中使用Google Spreadsheets.在构建库存管理系统时,我想知道在将数据导入MySQL时最佳实践是什么.
电子表格具有以下结构:
PartNo. | Vendor | Title | Quantity | Cost | Sum | EAN | Comment | Price
841750 | Volvo | Oil filter| 5 | 10 | 50 | 1234567812345 | | 18
20.1418 | MarinH | Light | 1 | 44 | 44 | 1234567812346 | | 80
Run Code Online (Sandbox Code Playgroud)
谷歌给我的意见是导出到csv文件,mysql可以读取,但是有一些更聪明的方法吗?
您也可以向我推荐一个数据库表结构:-)
我正在使用php中的csv导入脚本.它工作正常,除了字段开头的外来字符.
代码看起来像这样
if (($handle = fopen($filename, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
$teljing[] = $data;
fclose($handle);
}
Run Code Online (Sandbox Code Playgroud)
这是一个显示我的问题的数据示例
føroyskir stavir, "Kr. 201,50"
óvirkin ting, "Kr. 100,00"
Run Code Online (Sandbox Code Playgroud)
这将导致以下结果
array
(
[0] => array
(
[0] => 'føroyskir stavir',
[1] => 'Kr. 201,50'
)
[1] => array
(
[0] => 'virkin ting', <--- Should be 'óvirkin ting'
[1] => 'Kr. 100,00'
)
)
Run Code Online (Sandbox Code Playgroud)
我已经在php.net的一些评论中看到了这种行为,我试图ini_set('auto_detect_line_endings',TRUE);检测行结尾.没有成功.
有谁熟悉这个问题?
编辑:
谢谢你,这个问题现在解决了.
setlocale(LC_ALL, 'en_US.UTF-8');
是解决方案.
我知道sql注入已经在stackoverflow上讨论了很多次.
使用此方法有什么缺点
foreach($_POST as &$value)
$value = mysql_real_escape_string($value);
Run Code Online (Sandbox Code Playgroud)
它只有两行,看起来使用起来非常方便,但我认为这不是一个非常常用的方法.
并且请不要将讨论转变为准备好的陈述和PDO,即使它可能被认为是最佳实践.