|
|
|
รบกวนด้วยค่ะ ไม่สามารถแก้ไขรูปภาพลงฐานข้อมูลได้ค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php require_once('../Connections/network.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE managenews SET Title=%s, NewsDate=%s, Detail=%s, Attach_File=%s WHERE NewsID=%s",
GetSQLValueString($_POST['Title'], "text"),
GetSQLValueString($_POST['NewsDate'], "text"),
GetSQLValueString($_POST['Detail'], "text"),
GetSQLValueString($_POST['Attach_File'], "text"),
GetSQLValueString($_POST['NewsID'], "int"));
mysql_select_db($database_network, $network);
$Result1 = mysql_query($updateSQL, $network) or die(mysql_error());
}
mysql_select_db($database_network, $network);
$query_editnews = "SELECT * FROM managenews";
$editnews = mysql_query($query_editnews, $network) or die(mysql_error());
$row_editnews = mysql_fetch_assoc($editnews);
$totalRows_editnews = mysql_num_rows($editnews);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Title:</td>
<td><input type="text" name="Title" value="<?php echo htmlentities($row_editnews['Title'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">NewsDate:</td>
<td><input type="text" name="NewsDate" value="<?php echo htmlentities($row_editnews['NewsDate'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">Detail:</td>
<td><textarea name="Detail" cols="50" rows="5"><?php echo htmlentities($row_editnews['Detail'], ENT_COMPAT, 'utf-8'); ?></textarea> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Picture</td>
<td><p>
<input type="file" name="Attach_File">
</p>
<p><img src="myfile/<?php echo $row_editnews
["Attach_File"];?>"><br>
</p></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Update record" />
<input type="hidden" name="Attach_File" value="<?php echo htmlentities($row_editnews['Attach_File'], ENT_COMPAT, 'utf-8'); ?>" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="NewsID" value="<?php echo $row_editnews['NewsID']; ?>" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($editnews);
?>
ตรงAttach_File ค่ะ ไม่ทราบว่าต้องเขียนcodeยังไงถึงทำให้แก้ไขข้อมูลลงฐานข้อมูลได้คะ สามารถเอารูปมาโชว์ได้ในหน้าแก้ไข แต่พอเปลี่ยนรูปแล้วทำไม่ได้ค่ะ
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2014-09-07 14:36:01 |
By :
KwangKie |
View :
783 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
079.<input type="file" name="Attach_File">
088.<input type="hidden" name="Attach_File" value="<?php echo htmlentities($row_editnews['Attach_File'], ENT_COMPAT, 'utf-8'); ?>" />
ทำไม name ถึงเหมือนกันครับ
ปล. input type='file' ตัวรับจะเป็น $_FILES['Attach_File'];
ลองใช้คำสั่ง print_r($_FILES); เพื่อตรวจสอบค่าไฟล์ที่ส่งมาครับ
|
ประวัติการแก้ไข 2014-09-07 14:55:41
|
|
|
|
Date :
2014-09-07 14:52:47 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|