|
|
|
อยากทำโค๊ด Text Field ที่สามารถเพิ่มได้ แต่เกิดปัญหา ช่วยที |
|
|
|
|
|
|
|
อยากทำโค๊ด Text Field ที่สามารถเพิ่มได้ แต่เกิดปัญหา ข้อมูล Text Field เข้าแค่บรรทัดเดียว นะครับ
<?php require_once('Connections/Connection.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 stok (List, Number, Type, Piece) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['List'], "text"),
GetSQLValueString($_POST['Number'], "text"),
GetSQLValueString($_POST['Type'], "text"),
GetSQLValueString($_POST['Piece'], "text"));
mysql_select_db($database_Connection, $Connection);
$Result1 = mysql_query($insertSQL, $Connection) or die(mysql_error());
$insertGoTo = "index.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<script>
function CreateTextbox(){
document.getElementById('tbox1').innerHTML+="<input type=\"text\" name=\""+document.getElementById('val').value+"\" /><br/>\n";
document.getElementById('tbox2').innerHTML+="<input type=\"text\" name=\""+document.getElementById('val').value+"\" /><br/>\n";
document.getElementById('tbox3').innerHTML+="<input type=\"text\" name=\""+document.getElementById('val').value+"\" /><br/>\n";
document.getElementById('tbox4').innerHTML+="<input type=\"text\" name=\""+document.getElementById('val').value+"\" /><br/>\n";
document.getElementById('val'). value++;
}
</script>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="689" height="67" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="150"><div align="center">รายการ</div></td>
<td width="144"><div align="center">จำนวน</div></td>
<td width="144"><div align="center">ชนิด</div></td>
<td width="144"><div align="center">ราคา</div></td>
<td width="131"> </td>
</tr>
<tr>
<td>
<div id="tbox1" align="center">
<input name="List" type="text" id="List" />
</div> </div></td>
<td>
<div id="tbox2" align="center">
<input name="Number" type="text" id="Number" />
</div>
</div></td>
<td>
<div id="tbox3" align="center">
<input name="Type" type="text" id="Type" />
</div>
</div></td>
<td><div id="tbox4" align="center">
<input name="Piece" type="text" id="Piece" />
</div></td>
<td><input name="hidden" type="hidden" id="val" value="1" />
<input name="Button" type="button" onclick="CreateTextbox()" value="สร้าง textbox"/></td>
</tr>
<tr>
<td colspan="2">
<div align="center"></div></td>
<td>
<label></label>
<div align="center">รวม</div></td><td><div align="center">
<input name="textfield5" type="text" />
</div></td>
<td> </td>
</tr>
<tr>
<td colspan="5"><div align="center">
<input type="hidden" name="MM_insert" value="form1" />
<input type="submit" name="Submit" value="ส่งข้อมูล" />
</div></td>
</tr>
</table>
<br />
<label></label>
</form>
</body>
</html>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-06-04 13:52:45 |
By :
13Baht |
View :
1011 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองอันนี้นะ
Code (PHP)
<script type="text/javascript"><!--
var gFiles = 0;
function addFile() {
var li = document.createElement('li');
li.setAttribute('id', 'file-' + gFiles);
li.innerHTML = 'ชื่อวิชา:<input type="text" name="name[]"> รหัสวิชา:<input type="text" name="sname[]"> หน่วยกิต:<input type="text" name="noykid[]"> เกรด:<input type="text" name="grade[]"><span onclick="removeFile(\'file-' + gFiles + '\')" style="cursor:pointer;"> <img src="pic/remove.gif" border="0"> </span>';
document.getElementById('files-root').appendChild(li);
gFiles++;
}
function removeFile(aId) {
var obj = document.getElementById(aId);
obj.parentNode.removeChild(obj);
}
--></script>
<span onclick="addFile()" style="cursor:pointer;"><img src="pic/add_now.gif" border="0"> <hr></span>
</p><ol id="files-root">
ปีการศึกษา:<input type="text" name="year">
ตัวอย่าง 2/2552
<p>
<hr>
<li>ชื่อวิชา:<input type="text" name="name[]">
รหัสวิชา:<input type="text" name="sname[]">
หน่วยกิต:<input type="text" name="noykid[]">
เกรด:<input type="text" name="grade[]">
</ol>
<CENTER><input type="submit" value="Submit" /></CENTER>
|
|
|
|
|
Date :
2010-06-05 16:07:35 |
By :
Ninezy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|