有没有一种方法可以格式化一个列表,以便我可以通过SQL插入它?使用PHP格式化文本
我目前的列表格式是test:test
,我希望能够格式化它,以便将其插入到我的数据库中。
INSERT INTO `test` (`user`, `file`) VALUES
('test', 'test'),
('test2', 'test2'),
('[email protected]', 'test3');
这是可能的吗?
<?
if($_POST['oldlist']){
$sql = "SELECT * FROM test WHERE user='$_POST[oldlist]'";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result) > 0) { echo "exists";} else {
$sqlq = "INSERT INTO test (`user` ,`file`)
VALUES ('$_POST[oldlist]');";
$add = mysql_query($sqlq) or die(mysql_error());
if($add){echo "done";}else {echo "failed";}
}}
?>
这是什么意思?我希望能够发布一个列表并将其插入到我的数据库中,但它必须先格式化。
注意SQL注入! – Asaph 2009-11-11 04:50:36
这是我个人使用的,没有任何公开的。 – Homework 2009-11-11 04:51:10
你可以在php中使用explode()。 – sathish 2009-11-11 04:52:34