ช่วยดูโค้ด ให้หน่อยค่ะ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ช่วยดูโค้ด ให้หน่อยค่ะ
ช่วยดูโค้ด ให้หน่อยค่ะ
Copy
หน้าเพิ่มข้อมูล loans_insert.php
<?php require_once('../Connections/connection.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;
}
}
mysql_select_db($database_connection, $connection);
$query_member = "SELECT Members_name FROM members";
$member = mysql_query($query_member, $connection) or die(mysql_error());
$row_member = mysql_fetch_assoc($member);
$totalRows_member = mysql_num_rows($member);
$colname_rice = "-1";
if (isset($_GET['Loans_id'])) {
$colname_rice = $_GET['Loans_id'];
}
mysql_select_db($database_connection, $connection);
$query_rice = sprintf("SELECT * FROM loans WHERE Loans_id = %s", GetSQLValueString($colname_rice, "text"));
$rice = mysql_query($query_rice, $connection) or die(mysql_error());
$row_rice = mysql_fetch_assoc($rice);
$totalRows_rice = mysql_num_rows($rice);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$_POST['Loans_interest']=$_POST['Loans_money']*0.01*6;
$_POST['Loans_balance']=$_POST['Loans_money']+$_POST['Loans_interest'];
$arr_loanDate=explode("-",$_POST['Loans_date']); // แยกแต่ละค่าด้วย -
$_POST['Loans_date']=$arr_loanDate[2]."-".$arr_loanDate[1]."-".$arr_loanDate[0];
$arr_deadlineDate=explode("-",$_POST['Loans_deadline']); // แยกแต่ละค่าด้วย -
$_POST['Loans_deadline']=$arr_deadlineDate[2]."-".$arr_deadlineDate[1]."-".$arr_deadlineDate[0];
$insertSQL = sprintf("INSERT INTO loans (Loans_id, Loans_date, Members_name, Loans_money, Loans_interest, Loans_balance, Loans_deadline, Loans_status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Loans_id'], "text"),
GetSQLValueString($_POST['Loans_date'], "date"),
GetSQLValueString($_POST['Members_name'], "text"),
GetSQLValueString($_POST['Loans_money'], "int"),
GetSQLValueString($_POST['Loans_interest'], "int"),
GetSQLValueString($_POST['Loans_balance'], "int"),
GetSQLValueString($_POST['Loans_deadline'], "date"),
GetSQLValueString($_POST['Loans_status'], "text"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
$insertGoTo = "loans_show.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ศูนย์ข้าวชุมชนตำบลโพกรวม</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="../datetimepicker-master/jquery.datetimepicker.css">
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script
src="../datetimepicker-master/build/jquery.datetimepicker.full.min.js"></script>
</head>
<body>
<div class="container" style="width:750px;">
<form action="loans_insert.php"class="form-inline" method="post" name="form1" id="form1">
<table width="800" align="center">
<tr valign="baseline">
<td colspan="3" align="center" nowrap="nowrap">ข้อมูลการกู้ยืมทุนกองทุน</td>
</tr>
<tr valign="baseline">
<td colspan="3" align="center" nowrap="nowrap"><p align="center">อัตราดอกเบี้ย>>ร้อยละ 1 บาทต่อเดือน</p></td>
</tr>
<tr valign="baseline">
<td width="138" align="right" nowrap="nowrap">เลขที่สัญญา :</td>
<td colspan="2"><input type="text" name="Loans_id" value="" size="10" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">วงเงินกู้ :</td>
<td colspan="2"><input name="Loans_money" type="text" value="" size="10" />
( ไม่เกิน 5,000 บาท ต่อคน )</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ชื่อสมาชิกศูนย์ข้าว :</td>
<td colspan="2">
<label for="Members_name"></label>
<select name="Members_name" id="Members_name">
<?php
do {
?>
<option value="<?php echo $row_member['Members_name']?>"<?php if (!(strcmp($row_member['Members_name'], $row_member['Members_name']))) {echo "selected="selected"";} ?>><?php echo $row_member['Members_name']?></option>
<?php
} while ($row_member = mysql_fetch_assoc($member));
$rows = mysql_num_rows($member);
if($rows > 0) {
mysql_data_seek($member, 0);
$row_member = mysql_fetch_assoc($member);
}
?>
</select>
<label for="Member_name"></label></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">วันทำสัญญา :</td>
<td width="127"> <input type="text" name="Loans_date" id="Loans_date"
class="form-control input-sm" onchange="date_add(this.value,'-','dmy','Loans_deadline',null,6)" > </td>
<td width="408">
กำหนดคืน:
<input type="text" name="Loans_deadline" id="Loans_deadline"
class="form-control input-sm" > (สิ้นสุดสัญญา 6 เดือน)</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">สถานกู้ยืม :</td>
<td colspan="2"><select name="Loans_status" id="Loans_status" title="<?php echo $row_loans_insert['Loans_status']; ?>" >
<option value="no">ยังไม่ได้ชำระเงิน</option>
<option value="yes">ชำระเงินแล้ว</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td colspan="2"><input type="submit" value="เพิ่มข้อมูล" /></td>
</tr>
</table>
<table width="800" border="0" align="center">
<tr>
<td align="right"><a href="admin_page.php">กลับเมนูหลัก</a></td>
</tr>
</table>
<p>
<input type="hidden" name="MM_insert" value="form1" />
</p>
</form>
</div>
<script type="text/javascript">
var date_add = function(date1,separate,format,targetObj,
addDate,addMonth,addYear
){
separate = typeof separate !== 'undefined' ? separate : '-';
format = typeof format !== 'undefined' ? format : 'dmy';
targetObj = typeof targetObj !== 'undefined' ? targetObj : null;
addDate = typeof addDate !== 'undefined' ? addDate : null;
addMonth = typeof addMonth !== 'undefined' ? addMonth : null;
addYear = typeof addYear !== 'undefined' ? addYear : null;
var s_date=date1;
var arr_s_date = s_date.split(separate);
var new_s_date = arr_s_date[format.indexOf('m')]
+'/'+arr_s_date[format.indexOf('d')]
+'/'+arr_s_date[format.indexOf('y')];
var e_date = new Date(new_s_date);
if(addDate){
e_date.setDate(e_date.getDate() + addDate);
}
if(addMonth){
e_date.setMonth(e_date.getMonth() + addMonth);
}
if(addYear){
e_date.setFullYear(e_date.getFullYear() + addYear);
}
function pad(s) { return (s < 10) ? '0' + s : s; }
var new_t_date = [];
new_t_date[0]=(format.charAt(0)=='d')?pad(e_date.getDate()):
(format.charAt(0)=='m')?pad(e_date.getMonth()+1):e_date.getFullYear();
new_t_date[1]=(format.charAt(1)=='d')?pad(e_date.getDate()):
(format.charAt(1)=='m')?pad(e_date.getMonth()+1):e_date.getFullYear();
new_t_date[2]=(format.charAt(2)=='d')?pad(e_date.getDate()):
(format.charAt(2)=='m')?pad(e_date.getMonth()+1):e_date.getFullYear();
var returnValue=[new_t_date[0],new_t_date[1],new_t_date[2]].join(separate);
if(targetObj){
document.getElementById(targetObj).value = returnValue;
}else{
return returnValue;
}
return [new_t_date[0],new_t_date[1],new_t_date[2]].join(separate);
}
$(function(){
$("#Loans_date,#Loans_deadline").datetimepicker({
format:'d-m-Y', // รูปแบบวันที่
formatDate:'d-m-Y',
timepicker:false,
closeOnDateSelect:true,
});
});
</script>
</body>
</html>
<?php
mysql_free_result($member);
mysql_free_result($rice);
?>
หน้าค้นหา loans_show.php<?php require_once('../Connections/connection.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_insert"])) && ($_POST["MM_insert"] == "form2")) { $insertSQL = sprintf("INSERT INTO loans (Loans_id, Loans_date, Members_name, Loans_money, Loans_interest, Loans_balance, Loans_deadline, Loans_status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['Loans_id'], "text"), GetSQLValueString($_POST['Loans_date'], "date"), GetSQLValueString($_POST['Members_name'], "text"), GetSQLValueString($_POST['Loans_money'], "int"), GetSQLValueString($_POST['Loans_interest'], "int"), GetSQLValueString($_POST['Loans_balance'], "int"), GetSQLValueString($_POST['Loans_deadline'], "date"), GetSQLValueString($_POST['Loans_status'], "text")); mysql_select_db($database_connection, $connection); $Result1 = mysql_query($insertSQL, $connection) or die(mysql_error()); $insertGoTo = "loans_show.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } $colname_Recordset1 = "-1"; if (isset($_POST['word'])) { $colname_Recordset1 = $_POST['word']; } mysql_select_db($database_connection, $connection); $query_Recordset1 = sprintf("SELECT * FROM loans WHERE Members_name LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text")); $Recordset1 = mysql_query($query_Recordset1, $connection) 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>ศูนย์ข้าวชุมชนตำลบโพกรวม</title> </head> <body> <form id="form1" name="form1" method="post" action="loans_show.php"> <center> <p> <label for="word">ค้นหาเลขที่สัญญาและชื่อสมาชิก :</label> <input type="text" name="word" id="word" /> <input type="submit" name="button" id="button" value="ค้นหา" /> </p> <table width="900" border="1" align="center"> <tr align="center"> <td>เลขที่สัญญา</td> <td>วันทำสัญญา</td> <td>ชื่อ-สกุลสมาชิก</td> <td>วงเงินกู้</td> <td>ดอกเบี้ย</td> <td>ยอดเงินคืน</td> <td>กำหนดคืน</td> <td>สถานะกู้ยืม</td> <td colspan="3">เพิ่ม / แก้ไข / ลบ</td> </tr> <?php do { ?> <tr align="center"> <td><?php echo $row_Recordset1['Loans_id']; ?></td> <td><?php echo date("d-m-Y",strtotime($row_Recordset1['Loans_date'])); ?></td> <td><?php echo $row_Recordset1['Members_name']; ?></td> <td><?php echo $row_Recordset1['Loans_money']; ?></td> <td><?php echo $row_Recordset1['Loans_interest']; ?></td> <td><?php echo $row_Recordset1['Loans_balance']; ?></td> <td><?php echo date("d-m-Y",strtotime($row_Recordset1['Loans_deadline'])); ?></td> <td><?php echo $row_Recordset1['Loans_status']; ?></td> <td><a href="loans_insert.php"><img src="../img/Add.png" width="30" height="28" /></a></td> <td><a href="loans_edit.php?Loans_id=<?php echo $row_Recordset1['Loans_id']; ?>"><img src="../img/Edit.png" width="30" height="28" /></a></td> <td><a href="loans_delete.php?Loans_id=<?php echo $row_Recordset1['Loans_id']; ?>"><img src="../img/delete.png" width="30" height="28" /></a></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <br><br> </form> <p> </p> </body> </html> <?php mysql_free_result($Recordset1); ?>
ออกแบบหน้าตาโปรแกรมในword ให้ค้นหากับเพิ่มข้อมูลอยู่ในหน้าเดียวกัน แต่พอทำอยู่หน้าเดียวกันแล้ว เพิ่มได้แต่ค้นหาไม่แสดงข้อมูล

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ