|
|
|
Syntex error ครับ แบบนี้ผิดตรงไหนครับ รบกวนชวยชี้แนะหน่อยครับ |
|
|
|
|
|
|
|
รูปประกอบ
นี่โค้ดครับ
Code (PHP)
<?php require_once('../../Connections/myconnect.php'); ?>
<?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"] == "form1")) {
$updateSQL = sprintf("UPDATE bmi_avad SET avad_detail=%s, BMI_id=%s WHERE avad_id=%s",
GetSQLValueString($_POST['avad_detail'], "text"),
GetSQLValueString($_POST['BMI_id'], "int"),
GetSQLValueString($_POST['avad_id'], "int"));
mysql_select_db($database_myconnect, $myconnect);
$Result1 = mysql_query($updateSQL, $myconnect) or die(mysql_error());
$updateGoTo = "bmi_category.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_GET['avad_id'])) {
$colname_Recordset1 = $_GET['avad_id'];
}
mysql_select_db($database_myconnect, $myconnect);
$query_Recordset1 = "SELECT * FROM bmi_avad WHERE avad_id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $myconnect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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">Avad_id:</td>
<td><?php echo $row_Recordset1['avad_id']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Avad_detail:</td>
<td><input type="text" name="avad_detail" value="<?php echo htmlentities($row_Recordset1['avad_detail'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">BMI_id:</td>
<td><input type="text" name="BMI_id" value="<?php echo htmlentities($row_Recordset1['BMI_id'], 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="avad_id" value="<?php echo $row_Recordset1['avad_id']; ?>" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Tag : PHP, HTML, jQuery
|
|
|
|
|
|
Date :
2019-06-18 16:43:39 |
By :
113819 |
View :
674 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เข้าใจว่าคงใช้ฟังก์ชั่น sprintf(); เหมือนข้างบน แต่ copy มาไม่หมด
Code (PHP)
$query_Recordset1 = sprintf(" SELECT * FROM bmi_avad WHERE avad_id = %s "
, GetSQLValueString($colname_Recordset1, "int")
);
ปล. ถ้าหากเพิ่งเริ่มเขียนโปรแกรม ควรอัพเดทการใช้งานฟังก์ชั่นต่างๆ ให้ทันสมัยด้วยนะครับ เช่น การเชื่อมต่อ DB ก็ไปศึกษา mysqli_???(); หรือ PDO ก็จะดีกว่า
|
|
|
|
|
Date :
2019-06-18 17:12:50 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2019-06-18 18:26:36 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|