|
|
|
อัพเดทแล้วค่าของรูปภาพเป็นค่าว่าง อยากให้เมื่ือกดอัพเดทเป็นรูปเดิม ช่วยแนะนำมือใหม่ให้หน่อยครับ |
|
|
|
|
|
|
|
อยากให้เมื่อกด update แล้วไฟล์เก่าที่อัพไป ยังอยู่เหมือนเดิมครับ
เช่น เมื่อผมเพิ่มข้อมูลเข้าไปแล้ว แล้วพอมาแก้ไข
ผมแก้ไข แค่ textbox ยี่ห้อ เมื่อกดอัพเดท แล้วไฟล์รูปภาพจะหายถ้าเราไม่เลือกใหม่ครับ
อยากให้ไฟล์เดิมยังอยู่แม้จะไม่เลือกรุปใหม่
ไฟล์ editmain.php
Code (PHP)
<?php require_once('../Connections/ConnectSW.php'); ?>
<?php include("dw-upload.inc.php"); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "admin";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "indexsrisawat.dwt.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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"] == "form2")) {
$updateSQL = sprintf("UPDATE datacar SET car_id=%s, pic_car=%s, data_brand=%s, data_gene=%s, data_year=%s, data_pricesell=%s, data_cate=%s WHERE code_car=%s",
GetSQLValueString($_POST['car_id'], "int"),
GetSQLValueString(dwUpload($_FILES['pic_car']), "text"),
GetSQLValueString($_POST['data_brand'], "text"),
GetSQLValueString($_POST['data_gene'], "text"),
GetSQLValueString($_POST['data_year'], "text"),
GetSQLValueString($_POST['data_pricesell'], "text"),
GetSQLValueString($_POST['data_cate'], "text"),
GetSQLValueString($_POST['code_car'], "int"));
mysql_select_db($database_ConnectSW, $ConnectSW);
$Result1 = mysql_query($updateSQL, $ConnectSW) or die(mysql_error());
$updateGoTo = "uploadmain.dwt.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_GET['codecar'])) {
$colname_Recordset1 = $_GET['codecar'];
}
mysql_select_db($database_ConnectSW, $ConnectSW);
$query_Recordset1 = sprintf("SELECT * FROM datacar WHERE code_car = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $ConnectSW) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);$colname_Recordset1 = "-1";
?>
<!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" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<style type="text/css">
@import url("../buttons1.css");
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
color: #FFF;
}
.dddd {
color: #FFF;
font-weight: bold;
font-size: 24px;
}
.sss {
color: #000;
}
.over {
background-color: #69F;
}
</style>
<STYLE type=text/css>
.link_12_dark_blue:link {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#0066CC;
}
.link_12_dark_blue:visited {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#0066CC;
}
.link_12_dark_blue:active {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#0066CC;
}
.link_12_dark_blue:hover {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#FF0000;
}
</STYLE>
</head>
<body background="../pmj/workshop/20-2/bg.jpg">
<table width="1100" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<th scope="col"><img src="../topmain4.jpg" width="1100" height="200" /></th>
</tr>
<tr>
<th scope="row" class="sss" align="right" bgcolor="#6699FF" >ยินดีต้อนรับ คุณ:<?php echo $_SESSION['MM_name_ac']; ?>[สถานะ : <?php echo $_SESSION['MM_UserType']; ?>]
<input name="btnlogout" type="button" class="button-tiny" id="btnlogout" value="LOG OUT!" onclick='location.replace("logout.php")' />
</tr>
<tr>
<th bgcolor="#333333" scope="row"><span class="dddd">แก้ไขข้อมูลการอัพโหลดรูปภาพ(Main)</span></th>
</tr>
<tr>
<th align="center" class="sss" bgcolor="#CCE3E9" scope="row">
<table width="1100" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="left" scope="col"><a href="uploadmain.dwt.php" class="link_12_dark_blue" style="text-decoration: none;"><<<BACK>>><br />
</a>
<form id="form1" name="form1" method="post" action="">
</form>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form2" id="form2">
<table align="center" onmouseover="className="over"" onmouseout="className=""" frame="box" >
<tr valign="baseline">
<td align="right" nowrap="nowrap" bgcolor="#CCE3E9">รหัสรถยนต์:</td>
<td><input type="text" name="car_id" value="<?php echo htmlentities($row_Recordset1['car_id'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" bgcolor="#CCE3E9">รูปภาพ:</td>
<td><input type="file" name="pic_car" value="<?php echo htmlentities($row_Recordset1['pic_car'], ENT_COMPAT, 'utf-8'); ?>" size="32" /><?php echo htmlentities($row_Recordset1['pic_car'], ENT_COMPAT, 'utf-8'); ?> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" bgcolor="#CCE3E9">ยี่ห้อ:</td>
<td><input type="text" name="data_brand" value="<?php echo htmlentities($row_Recordset1['data_brand'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" bgcolor="#CCE3E9">แบบ(รุ่น):</td>
<td><input type="text" name="data_gene" value="<?php echo htmlentities($row_Recordset1['data_gene'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" bgcolor="#CCE3E9">ปี:</td>
<td><input type="text" name="data_year" value="<?php echo htmlentities($row_Recordset1['data_year'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" bgcolor="#CCE3E9">ราคาขาย:</td>
<td><input type="text" name="data_pricesell" value="<?php echo htmlentities($row_Recordset1['data_pricesell'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" bgcolor="#CCE3E9">ประเภท:</td>
<td><select type="text" name="data_cate" value="<?php echo htmlentities($row_Recordset1['data_cate'], ENT_COMPAT, 'utf-8'); ?>" /><option value="<?php echo htmlentities($row_Recordset1['data_cate'], ENT_COMPAT, 'utf-8'); ?>" hidden="" selected="selected"><?php echo htmlentities($row_Recordset1['data_cate'], ENT_COMPAT, 'utf-8'); ?></option>
<option value="รถเก๋ง">รถเก๋ง</option>
<option value="รถกระบะ">รถกระบะ</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" class="button-group" value="Update record" style="width:100px;height:40px" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form2" />
<input type="hidden" name="code_car" value="<?php echo $row_Recordset1['code_car']; ?>" />
</form>
<p> </p>
<a href="reservmenu.dwt.php"> </a></th>
</tr>
</table></th>
</tr>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
-------------------------------------------------------------------------------------------------------------------------------------
เรียกใช้ไฟล์ dw-upload.inc.php
Code (PHP)
<?php
function dwUpload($file,$path="./img-products/"){
if(@copy($file['tmp_name'],$path.$file['name'])){
@chmod($path.$file,0777);
return $file['name'];
}else{
return false;
}
}
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2016-11-30 19:53:17 |
By :
tomzone2 |
View :
1243 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ dreamwaver ใช่มั้ยย
|
|
|
|
|
Date :
2016-11-30 21:16:28 |
By :
Luz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
if(!empty($_FILES['pic_car']['tmp_name])
{
$updateSQL = sprintf("UPDATE datacar SET car_id=%s, pic_car=%s, data_brand=%s, data_gene=%s, data_year=%s, data_pricesell=%s, data_cate=%s WHERE code_car=%s",
GetSQLValueString($_POST['car_id'], "int"),
GetSQLValueString(dwUpload($_FILES['pic_car']), "text"),
GetSQLValueString($_POST['data_brand'], "text"),
GetSQLValueString($_POST['data_gene'], "text"),
GetSQLValueString($_POST['data_year'], "text"),
GetSQLValueString($_POST['data_pricesell'], "text"),
GetSQLValueString($_POST['data_cate'], "text"),
GetSQLValueString($_POST['code_car'], "int"));
mysql_select_db($database_ConnectSW, $ConnectSW);
$Result1 = mysql_query($updateSQL, $ConnectSW) or die(mysql_error());
}else{
$updateSQL = sprintf("UPDATE datacar SET car_id=%s,data_brand=%s, data_gene=%s, data_year=%s, data_pricesell=%s, data_cate=%s WHERE code_car=%s",
GetSQLValueString($_POST['car_id'], "int"),
GetSQLValueString($_POST['data_brand'], "text"),
GetSQLValueString($_POST['data_gene'], "text"),
GetSQLValueString($_POST['data_year'], "text"),
GetSQLValueString($_POST['data_pricesell'], "text"),
GetSQLValueString($_POST['data_cate'], "text"),
GetSQLValueString($_POST['code_car'], "int"));
mysql_select_db($database_ConnectSW, $ConnectSW);
$Result1 = mysql_query($updateSQL, $ConnectSW) or die(mysql_error());
}
ตอบในโทรศัพท์ ไปทำโค้ดไห้มันสั้นเองนะ 55
|
ประวัติการแก้ไข 2016-11-30 23:31:38
|
|
|
|
Date :
2016-11-30 23:26:46 |
By :
Luz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|