|
 |
|
ช่วยหน่อยน่ะค่ะหากเราต้องการ Insert sql โดยการที่เรากดปุ่ม Insert เพียงครั้งเดียวค่ะ |
|
 |
|
|
 |
 |
|
textbox Id_criterion ต้องสร้างเป็น array น่ะครับ
ตัวอย่างน่ะครับ ลองไปประยุกต์ต่อดู
Code (PHP)
<form name="form1" action="" method="post">
Id_dep:<input type="textbox" name="Id_dep"><br>
Id_indicator:<input type="textbox" name="Id_indicator"><br>
Id_criterion:<input type="textbox" name="Id_criterion[]"><br>
Id_criterion:<input type="textbox" name="Id_criterion[]"><br>
Id_criterion:<input type="textbox" name="Id_criterion[]"><br>
Id_criterion:<input type="textbox" name="Id_criterion[]"><br>
Id_criterion:<input type="textbox" name="Id_criterion[]"><br>
<inpu type="submit">
</form>
<?
if($_POST['Id_dep'] !="" && $_POST['Id_indicator'] !="" && count($_POST['Id_criterion'])>0)
{
for($i=0;$i<count($_POST['Id_criterion']);$i++)
{
if($_POST['Id_criterion'][$i] !="")
{
mysql_query("insert into (id_dep,Id_indicator,Id_criterion)values('".$_POST['Id_dep']."','".$_POST['Id_indicator']."','".$_POST['Id_criterion'][$i]."')");/// ไปต่อเองน่ะครับ
}
}
}
?>
|
ประวัติการแก้ไข 2012-03-16 01:49:43
 |
 |
 |
 |
Date :
2012-03-16 01:48:28 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดหน้านี้จะประมาณนี้อ่ะค่ะ
Code (PHP)
<?php require_once('../Connections/rs_qa.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "../index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
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_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tbassessment (Id_dep, Id_indicator, Id_criterion) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['Id_dep'], "text"),
GetSQLValueString($_POST['Id_indicator'], "text"),
GetSQLValueString($_POST['Id_criterion'],"text"));
mysql_select_db($database_rs_qa, $rs_qa);
$Result1 = mysql_query($insertSQL, $rs_qa) or die(mysql_error());
}
$colname_rs_lia = "-1";
if (isset($_GET['Id_indicator'])) {
$colname_rs_lia = $_GET['Id_indicator'];
}
mysql_select_db($database_rs_qa, $rs_qa);
$query_rs_lia = sprintf("SELECT * FROM tbliability WHERE Id_indicator = %s", GetSQLValueString($colname_rs_lia, "text"));
$rs_lia = mysql_query($query_rs_lia, $rs_qa) or die(mysql_error());
$row_rs_lia = mysql_fetch_assoc($rs_lia);
$totalRows_rs_lia = mysql_num_rows($rs_lia);
$colname_rs_indicator= "-1";
if (isset($_GET['Id_indicator'])) {
$colname_rs_indicator = $_GET['Id_indicator'];
}
mysql_select_db($database_rs_qa, $rs_qa);
$query_rs_indicator = $query_rs_indicator = sprintf("SELECT * FROM tbindicator WHERE Id_indicator = %s", GetSQLValueString($colname_rs_indicator, "text"));
$rs_indicator = mysql_query($query_rs_indicator, $rs_qa) or die(mysql_error());
$row_rs_indicator = mysql_fetch_assoc($rs_indicator);
$totalRows_rs_indicator = mysql_num_rows($rs_indicator);
$colname_rs_criterion = "-1";
if (isset($_GET['Id_indicator'])) {
$colname_rs_criterion = $_GET['Id_indicator'];
}
mysql_select_db($database_rs_qa, $rs_qa);
$query_rs_criterion = sprintf("SELECT * FROM tbcriterion WHERE Id_indicator = %s", GetSQLValueString($colname_rs_criterion, "text"));
$rs_criterion = mysql_query($query_rs_criterion, $rs_qa) or die(mysql_error());
$row_rs_criterion = mysql_fetch_assoc($rs_criterion);
$totalRows_rs_criterion = mysql_num_rows($rs_criterion);
$currentPage = $_SERVER["PHP_SELF"];
?>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('../images/bt_2_01.png','../images/bt_2_02.png','../images/bt_2_03.png','../images/bt_2_05.png','../images/bt_2_06.png','../images/bt_2_07.png','../images/bt_2_08.png')">
<?
$Log_state=$_SESSION['MM_Log_state'];
$Id_dep=$_SESSION['MM_Id_dep'];
$Id_mas=$_SESSION['MM_Id_mas'];
$Name_attendant_1=$_SESSION['MM_Name_attendant_1'];
$Surname_attendant_1= $_SESSION['MM_Surname_attendant_1'];
$Email_attendant_1= $_SESSION['MM_Email_attendant_1'];
?>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Id_dep:</td>
<td><input type="" name="Id_dep" value="<?php echo $Id_dep ; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Id_indicator:</td>
<td><input type="text" name="Id_indicator" value="<?php echo $row_rs_indicator['Id_indicator']; ?>" size="32"></td>
</tr>
<?php do { ?>
<tr valign="baseline">
<td nowrap align="right">Id_criterion:</td>
<td><input type="text" name="Id_criterion" value="<?php echo $row_rs_criterion['Id_criterion']; ?>" size="32"></td>
</tr>
<?php } while ($row_rs_criterion = mysql_fetch_assoc($rs_criterion)); ?>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td>
<input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
<p> </p></td>
</tr>
</table></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
<?php
mysql_free_result($rs_lia);
mysql_free_result($rs_indicator);
mysql_free_result($rs_criterion);
?>
|
 |
 |
 |
 |
Date :
2012-03-16 10:47:41 |
By :
Noo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|