001.
<?php
002.
$hostname
=
"localhost"
;
003.
$user
=
"root"
;
004.
$password
=
"1234"
;
005.
$dbname
=
"project"
;
006.
$tbname
=
"news"
;
007.
mysql_connect(
$hostname
,
$user
,
$password
)
or
die
(
"Not Connection Mysql"
);
008.
mysql_select_db(
$dbname
)
or
die
(
"Not Select Date Base"
);
009.
mysql_query(
"SET character_set_results=utf8"
);
010.
mysql_query(
"SET character_set_client=utf8"
);
011.
mysql_query(
"SET character_set_connection=utf8"
);
012.
$date
=
date
(
'Y:m:d'
);
013.
$sql_insert
= sprintf("INSERT INTO news(
date
)
014.
vaule(
'%s'
)",
$_POST
[
'date'
]);
015.
016.
?>
017.
<?php
require_once
(
'Connections/mk.php'
); ?>
018.
<?php
019.
if
(!function_exists(
"GetSQLValueString"
)) {
020.
function
GetSQLValueString(
$theValue
,
$theType
,
$theDefinedValue
=
""
,
$theNotDefinedValue
=
""
)
021.
{
022.
if
(PHP_VERSION < 6) {
023.
$theValue
= get_magic_quotes_gpc() ?
stripslashes
(
$theValue
) :
$theValue
;
024.
}
025.
026.
$theValue
= function_exists(
"mysql_real_escape_string"
) ? mysql_real_escape_string(
$theValue
) : mysql_escape_string(
$theValue
);
027.
028.
switch
(
$theType
) {
029.
case
"text"
:
030.
$theValue
= (
$theValue
!=
""
) ?
"'"
.
$theValue
.
"'"
:
"NULL"
;
031.
break
;
032.
case
"long"
:
033.
case
"int"
:
034.
$theValue
= (
$theValue
!=
""
) ?
intval
(
$theValue
) :
"NULL"
;
035.
break
;
036.
case
"double"
:
037.
$theValue
= (
$theValue
!=
""
) ? doubleval(
$theValue
) :
"NULL"
;
038.
break
;
039.
case
"date"
:
040.
$theValue
= (
$theValue
!=
""
) ?
"'"
.
$theValue
.
"'"
:
"NULL"
;
041.
break
;
042.
case
"defined"
:
043.
$theValue
= (
$theValue
!=
""
) ?
$theDefinedValue
:
$theNotDefinedValue
;
044.
break
;
045.
}
046.
return
$theValue
;
047.
}
048.
}
049.
050.
mysql_select_db(
$database_mk
,
$mk
);
051.
$query_Recordset1
=
"SELECT * FROM news"
;
052.
$Recordset1
= mysql_query(
$query_Recordset1
,
$mk
)
or
die
(mysql_error());
053.
mysql_query(
"SET NAMES UTF8"
);
054.
$row_Recordset1
= mysql_fetch_assoc(
$Recordset1
);
055.
$totalRows_Recordset1
= mysql_num_rows(
$Recordset1
);
056.
057.
$editFormAction
=
$_SERVER
[
'PHP_SELF'
];
058.
if
(isset(
$_SERVER
[
'QUERY_STRING'
])) {
059.
$editFormAction
.=
"?"
. htmlentities(
$_SERVER
[
'QUERY_STRING'
]);
060.
}
061.
062.
if
((isset(
$_POST
[
"MM_insert"
])) && (
$_POST
[
"MM_insert"
] ==
"form1"
))
063.
{
064.
$insertSQL
= sprintf(
"INSERT INTO news (subject, name, detail) VALUES (%s, %s, %s)"
,
065.
GetSQLValueString(
$_POST
[
'subject'
],
"text"
),
066.
GetSQLValueString(
$_POST
[
'name'
],
"text"
),
067.
GetSQLValueString(
$_POST
[
'detail'
],
"text"
));
068.
069.
mysql_select_db(
$database_mk
,
$mk
);
070.
$Result1
= mysql_query(
$insertSQL
,
$mk
)
or
die
(mysql_error());
071.
072.
$insertGoTo
=
"testttttt.php"
;
073.
if
(isset(
$_SERVER
[
'QUERY_STRING'
])) {
074.
$insertGoTo
.= (
strpos
(
$insertGoTo
,
'?'
)) ?
"&"
:
"?"
;
075.
$insertGoTo
.=
$_SERVER
[
'QUERY_STRING'
];
076.
}
077.
header(sprintf(
"Location: %s"
,
$insertGoTo
));
078.
}
079.
080.
if
((isset(
$_POST
[
"MM_insert"
])) && (
$_POST
[
"MM_insert"
] ==
"form1"
)) {
081.
082.
$insertSQL
= sprintf(
"INSERT INTO news (subject, detail, `date`) VALUES (%s, %s, %s)"
,
083.
GetSQLValueString(
$_POST
[
'subject'
],
"text"
),
084.
GetSQLValueString(
$_POST
[
'detail'
],
"text"
),
085.
GetSQLValueString(
$_POST
[
'date'
],
"date"
));
086.
087.
mysql_select_db(
$database_mk
,
$mk
);
088.
$Result1
= mysql_query(
$insertSQL
,
$mk
)
or
die
(mysql_error());
089.
090.
$insertGoTo
=
"news_shows.php"
;
091.
if
(isset(
$_SERVER
[
'QUERY_STRING'
])) {
092.
$insertGoTo
.= (
strpos
(
$insertGoTo
,
'?'
)) ?
"&"
:
"?"
;
093.
$insertGoTo
.=
$_SERVER
[
'QUERY_STRING'
];
094.
}
095.
header(sprintf(
"Location: %s"
,
$insertGoTo
));
096.
}
097.
098.
mysql_select_db(
$database_mk
,
$mk
);
099.
$query_Recordset1
=
"SELECT * FROM news"
;
100.
$Recordset1
= mysql_query(
$query_Recordset1
,
$mk
)
or
die
(mysql_error());
101.
mysql_query(
"SET NAMES UTF8"
);
102.
$row_Recordset1
= mysql_fetch_assoc(
$Recordset1
);
103.
$totalRows_Recordset1
= mysql_num_rows(
$Recordset1
);
104.
?>
107.
<head>
108.
<meta http-equiv=Content-Type content=
"text/html; charset=utf-8"
>
109.
<title>Untitled Document</title>
110.
<style type=
"text/css"
>
111.
#form1 div p {
112.
color: #36C;
113.
font-size: 18;
114.
font-weight: bold;
115.
}
116.
#object {
117.
color: #FFF;
118.
}
119.
</style>
120.
</head>
121.
122.
123.
<body>
124.
<form action=
"<?php echo $editFormAction; ?>"
id=
"form1"
name=
"form1"
method=
"POST"
>
125.
<div align=
"center"
>
126.
<p>เพิ่มข่าวประชาสัมพันธ์</p>
127.
<table width=
"383"
border=
"0"
cellspacing=
"2"
cellpadding=
"0"
>
128.
<tr bgcolor=
"#92D3F3"
id=
"object"
>
129.
<td colspan=
"2"
><div align=
"center"
>กรุณากรอกรายละเอียดให้ครบถ้วน</div></td>
130.
</tr>
131.
<tr>
132.
<td width=
"125"
bgcolor=
"#92D3F3"
id=
"object"
><div align=
"center"
>หัวข้อ</div></td>
133.
<td width=
"258"
bgcolor=
"#B8DDEF"
><label
for
=
"subject"
></label>
134.
<input name=
"subject"
type=
"text"
id=
"subject"
size=
"30"
maxlength=
"30"
/></td>
135.
</tr>
136.
<tr>
137.
<td bgcolor=
"#92D3F3"
id=
"object"
><div align=
"center"
>รายละเอียด</div></td>
138.
<td bgcolor=
"#B8DDEF"
><label
for
=
"detail"
></label>
139.
<textarea name=
"detail"
cols=
"27"
rows=
"5"
id=
"detail"
></textarea></td>
140.
</tr>
141.
<tr>
142.
<td bgcolor=
"#92D3F3"
id=
"object"
><div align=
"center"
>ผู้เพิ่มข่าว</div></td>
143.
<td bgcolor=
"#B8DDEF"
><label
for
=
"name"
></label>
144.
<input name=
"name"
type=
"text"
id=
"name"
size=
"20"
maxlength=
"20"
/></td>
145.
</tr>
146.
<tr bgcolor=
"#92D3F3"
>
147.
<td colspan=
"2"
><div align=
"center"
>
148.
<input type=
"submit"
name=
"submit"
id=
"submit"
value=
"ยืนยัน"
/>
149.
</div></td>
150.
</tr>
151.
</table>
152.
</div>
153.
<input type=
"hidden"
name=
"MM_insert"
value=
"form1"
/>
154.
</form>
155.
</body>
156.
</html>
157.
<?php
158.
mysql_free_result(
$Recordset1
);
159.
?>