|
|
|
Update ข้อมูลได้แต่พอเลือกอัพเดตของช่องรูปภาพ ไม่ขึ้นครับ |
|
|
|
|
|
|
|
Code (PHP)
<?php ob_start(); ?>
<?php require_once('Connections/con_mysql.php'); ?>
<?php include("Upload.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 product SET prd_img=%s, prd_name=%s, prd_price=%s, prd_detill=%s WHERE id=%s",
GetSQLValueString(Upload($_FILES['prdImg']), "text"),
GetSQLValueString($_POST['prd_name'], "text"),
GetSQLValueString($_POST['prd_price'], "text"),
GetSQLValueString($_POST['prd_detill'], "text"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_con_mysql, $con_mysql);
$Result1 = mysql_query($updateSQL, $con_mysql) or die(mysql_error());
$updateGoTo = "for-admin.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_UpdateRecordset = "-1";
if (isset($_GET['prdid'])) {
$colname_UpdateRecordset = $_GET['prdid'];
}
mysql_select_db($database_con_mysql, $con_mysql);
$query_UpdateRecordset = sprintf("SELECT * FROM product WHERE id = %s", GetSQLValueString($colname_UpdateRecordset, "int"));
$UpdateRecordset = mysql_query($query_UpdateRecordset, $con_mysql) or die(mysql_error());
$row_UpdateRecordset = mysql_fetch_assoc($UpdateRecordset);
$totalRows_UpdateRecordset = mysql_num_rows($UpdateRecordset);
?><!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" enctype="multipart/form-data" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Id:</td>
<td><?php echo $row_UpdateRecordset['id']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Prd_img:</td>
<td><input type="file" name="prd_img" value="<?php echo htmlentities($row_UpdateRecordset['prd_img'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Prd_name:</td>
<td><input type="text" name="prd_name" value="<?php echo htmlentities($row_UpdateRecordset['prd_name'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Prd_price:</td>
<td><input type="text" name="prd_price" value="<?php echo htmlentities($row_UpdateRecordset['prd_price'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Prd_detill:</td>
<td><input type="text" name="prd_detill" value="<?php echo htmlentities($row_UpdateRecordset['prd_detill'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Update record" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="id" value="<?php echo $row_UpdateRecordset['id']; ?>" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($UpdateRecordset);
?>
Tag : PHP
|
|
|
|
|
|
Date :
2020-03-08 18:29:03 |
By :
kaila10 |
View :
557 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ข้อมูลส่วนอื่นพอกดแก้ไขแล้วกด save ก็จะอัพเดตใหม่หมดครับ
ยกเว้นรูปที่อัพเดตไม่ได้ ในฐานข้อมูลก็ไม่ขึ้นครับ
นี้ตารางฐานข้อมูลครับ
|
|
|
|
|
Date :
2020-03-08 18:34:32 |
By :
kaila10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|