01.
<?php
02.
03.
error_reporting
( E_ALL );
04.
include
(
"connect_db.php"
);
05.
06.
$text
=
"insert into table (data1) values ('insert into table (f1,f2,f3) values ('v1','v2','v3')'"
;
07.
08.
function
GetSQLValueString(
$theValue
,
$theType
,
$theDefinedValue
=
""
,
$theNotDefinedValue
=
""
)
09.
{
10.
if
(PHP_VERSION < 6) {
11.
$theValue
= get_magic_quotes_gpc() ?
stripslashes
(
$theValue
) :
$theValue
;
12.
}
13.
14.
$theValue
= function_exists(
"mysql_real_escape_string"
) ? mysql_real_escape_string(
$theValue
) : mysql_escape_string(
$theValue
);
15.
16.
switch
(
$theType
) {
17.
case
"text"
:
18.
$theValue
= (
$theValue
!=
""
) ?
"'"
.
$theValue
.
"'"
:
"NULL"
;
19.
break
;
20.
case
"long"
:
21.
case
"int"
:
22.
$theValue
= (
$theValue
!=
""
) ?
intval
(
$theValue
) :
"NULL"
;
23.
break
;
24.
case
"double"
:
25.
$theValue
= (
$theValue
!=
""
) ? doubleval(
$theValue
) :
"NULL"
;
26.
break
;
27.
case
"date"
:
28.
$theValue
= (
$theValue
!=
""
) ?
"'"
.
$theValue
.
"'"
:
"NULL"
;
29.
break
;
30.
case
"defined"
:
31.
$theValue
= (
$theValue
!=
""
) ?
$theDefinedValue
:
$theNotDefinedValue
;
32.
break
;
33.
}
34.
return
$theValue
;
35.
}
36.
37.
$insertSQL
= sprintf(
"INSERT INTO command (`cid` ,`site`,`comm`) VALUES (%s, %s, %s)"
,
38.
GetSQLValueString(NULL,
"int"
),
39.
GetSQLValueString(
"1"
,
"int"
),
40.
GetSQLValueString(
$text
,
"text"
));
41.
42.
$Result1
= mysql_query(
$insertSQL
)
or
die
(mysql_error());
43.
44.
45.
if
(
$Result1
){
echo
"<br/>Ok"
;}
else
{
echo
"<br/>No"
;}
46.
?>