รบกวนหน่อยครับบันทึกข้อมูลลงฐานข้อมูลไม่ได้ไม่รู้ว่าผิดตรงไหน
Code
<!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>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 14px;
}
</style>
</head>
<body>
<?php
include('includes/Config.php');
if($_POST[button] == 'Add'){
$txt_relate = $_POST[txt_relate];
$txt_old = $_POST[txt_old];
$txt_new = $_POST[txt_new];
$txt_tcb = $_POST[txt_tcb];
$txt_mac = $_POST[txt_mac];
$txt_s = $_POST[txt_s];
$brand = $_POST[brand];
$model = $_POST[model];
$txt_hdd = $_POST[txt_hdd];
$txt_ram = $_POST[txt_ram];
$cpubrand = $_POST[cpubrand];
$txt_cpus = $_POST[txt_cpus];
$txt_cpusp = $_POST[txt_cpusp];
$txt_ip = $_POST[txt_ip];
$txt_subnet = $_POST[txt_subnet];
$txt_gateway = $_POST[txt_gateway];
$txt_sw = $_POST[txt_sw];
$os = $_POST[os];
$txt_remark = $_POST[txt_remark];
$txt_floor = $_POST[txt_floor];
$txt_code = $_POST[txt_code];
$txt_point = $_POST[txt_point];
$role = $_POST[role];
$sql_insert = "INSERT INTO pc";
$sql_insert."(OldAsset,NewAsset,TCB,MAC,Serial,Brand,Model,HDD,RAM,CPUBrand,CPUSeries)";
$sql_insert."(CPUSpeed,IPAddress,Subnet,Gateway,SW,OS,Remark,Floor,CODE,Point,Role)";
$sql_insert."values('$txt_old','$txt_new','$txt_tcb','$txt_mac','$txt_s','$brand','$model','$txt_hdd')";
$sql_insert."('$txt_ram','$cpubrand','$txt_cpus','$txt_cpusp','$txt_address','$txt_subnet','$txt_gateway','$txt_sw','$os','$txt_remark')";
$sql_insert."('$txt_floor','$txt_code','$txt_point','$role')";
$sqlquery = mysql_db_query($dbname,$sql_insert);
if($sqlquery){
echo "OK..";
}else{
echo "Error";
}
}
?>
<form id="form1" name="form1" method="post" action="">
<table width="1080" border="1">
<tr>
<td width="79" height="52" align="center" bgcolor="#0000FF">Computer</td>
<td width="68" align="center" bgcolor="#0000FF">Monitor</td>
<td width="136" align="center" bgcolor="#0000FF"> WEB Camera</td>
<td width="141" align="center" bgcolor="#0000FF">Barcode reader</td>
<td width="97" align="center" bgcolor="#0000FF">Smart card reader</td>
<td width="119" align="center" bgcolor="#0000FF">Madnetic stripe reader</td>
<td width="67" align="center" bgcolor="#0000FF">Scanner</td>
<td width="132" align="center" bgcolor="#0000FF">Passbook printer</td>
<td width="183" align="center" bgcolor="#0000FF">Dot matrix printer</td>
</tr>
</table>
<table width="1080" border="1">
<tr>
<td colspan="4" bgcolor="#0033FF">Computer Case</td>
</tr>
<tr>
<td width="196" bgcolor="#00CCFF">Old Asset ID</td>
<td width="196" bgcolor="#00CCFF"><input type="text" name="txt_old" id="txt_old" /></td>
<td width="160" bgcolor="#00CCFF">Status</td>
<td width="500" bgcolor="#00CCFF"><select name="status" id="status">
<option value="Deployed">Deployed</option>
<option value="Tranfer">Tranfer</option>
</select></td>
</tr>
<tr>
<td bgcolor="#0099FF">New Asset ID</td>
<td bgcolor="#0099FF"><input type="text" name="txt_new" id="txt_new" /></td>
<td bgcolor="#0099FF">Relate CI</td>
<td bgcolor="#0099FF"><input type="text" name="txt_relate" id="txt_relate" /></td>
</tr>
<tr>
<td bgcolor="#00CCFF">TCB Name</td>
<td bgcolor="#00CCFF"><input type="text" name="txt_tcb" id="txt_tcb" /></td>
<td bgcolor="#00CCFF">Floor</td>
<td bgcolor="#00CCFF"><input type="text" name="txt_floor" id="txt_floor" /></td>
</tr>
<tr>
<td bgcolor="#0099FF">MAC Name</td>
<td bgcolor="#0099FF"><input type="text" name="txt_mac" id="txt_mac" /></td>
<td bgcolor="#0099FF">Location Code</td>
<td bgcolor="#0099FF"><input type="text" name="txt_code" id="txt_code" /></td>
</tr>
<tr>
<td bgcolor="#00CCFF">Serial No</td>
<td bgcolor="#00CCFF"><input type="text" name="txt_s" id="txt_s" /></td>
<td bgcolor="#00CCFF">End Point No</td>
<td bgcolor="#00CCFF"><input type="text" name="txt_point" id="txt_point" /></td>
</tr>
<tr>
<td bgcolor="#0099FF">Brand</td>
<td bgcolor="#0099FF"><select name="brand" id="brand">
<option value="null" selected="selected">Other</option>
<option value="Lenovo">Lenovo</option>
<option value="Dell">Dell</option>
<option value="Acer">Acer</option>
<option value="IBM">IBM</option>
</select></td>
<td bgcolor="#0099FF"> </td>
<td bgcolor="#0099FF"> </td>
</tr>
<tr>
<td bgcolor="#00CCFF">Model</td>
<td bgcolor="#00CCFF"><select name="model" id="model">
<option value="null">Other</option>
<option value="7303">7303</option>
</select></td>
<td bgcolor="#00CCFF"> </td>
<td bgcolor="#00CCFF"> </td>
</tr>
<tr>
<td bgcolor="#0099FF">HDD capacity</td>
<td bgcolor="#0099FF"><input type="text" name="txt_hdd" id="txt_hdd" /></td>
<td bgcolor="#0099FF"> </td>
<td bgcolor="#0099FF"> </td>
</tr>
<tr>
<td colspan="4" bgcolor="#0033FF">Processor & Memory</td>
</tr>
<tr>
<td bgcolor="#00CCFF">CPU Brand</td>
<td bgcolor="#00CCFF"><select name="cpubrand" id="cpubrand">
<option value="null">Other</option>
<option value="Intel">Intel</option>
</select></td>
<td bgcolor="#00CCFF">CPU Speed</td>
<td bgcolor="#00CCFF"><input type="text" name="txt_cpusp" id="txt_cpusp" /></td>
</tr>
<tr>
<td bgcolor="#0099FF">CPU Series</td>
<td bgcolor="#0099FF"><input type="text" name="txt_cpus" id="txt_cpus" /></td>
<td bgcolor="#0099FF">Ram</td>
<td bgcolor="#0099FF"><input type="text" name="txt_ram" id="txt_ram" /></td>
</tr>
<tr>
<td colspan="4" bgcolor="#0033FF">Network</td>
</tr>
<tr>
<td bgcolor="#00CCFF">IP Address</td>
<td bgcolor="#00CCFF"><input type="text" name="txt_ip" id="txt_ip" /></td>
<td bgcolor="#00CCFF">Default Gateway</td>
<td bgcolor="#00CCFF"><input type="text" name="txt_gateway" id="txt_gateway" /></td>
</tr>
<tr>
<td bgcolor="#0099FF">Switch port no</td>
<td bgcolor="#0099FF"><input type="text" name="txt_sw" id="txt_sw" /></td>
<td bgcolor="#0099FF">Subnetmark</td>
<td bgcolor="#0099FF"><input type="text" name="txt_subnet" id="txt_subnet" /></td>
</tr>
<tr>
<td colspan="4" bgcolor="#0033FF">Image</td>
</tr>
<tr>
<td bgcolor="#00CCFF">OS Partition</td>
<td bgcolor="#00CCFF"><select name="os" id="os">
<option value="null" selected="selected">Other</option>
<option value="Windows XP Service Pack 3">Windows XP Service Pack 3</option>
</select></td>
<td bgcolor="#00CCFF">Role(Funtion Title)</td>
<td bgcolor="#00CCFF"><select name="role" id="role">
<option value="null">For Brand</option>
<option value="BMO">BMO</option>
</select></td>
</tr>
<tr>
<td height="87" bgcolor="#0099FF">Remark</td>
<td colspan="3" bgcolor="#0099FF"><textarea name="txt_remark" id="txt_remark" cols="45" rows="5"></textarea></td>
</tr>
</table>
<p>
<input type="submit" name="button" id="button" value="Add" />
</p>
</form>
</body>
</html>
Quote: ไม่รู้ว่าผิดตรงไหน
Tag : PHP
Date :
2013-06-10 22:36:51
By :
cmsarin
View :
804
Reply :
9
$txt_relate = $_POST[txt_relate];
$_POST["txt_relate"]; << ใส่ ดับเบิลโคดด้วยครับทุกอันเลย ถ้ายังไม่ออกลองเอา ค่า $_POST มา echo ดู ว่าค่าถูกส่งมาไหมครับ
ประวัติการแก้ไข 2013-06-10 22:40:47
Date :
2013-06-10 22:39:25
By :
champkung226
ลองเอา ค่า $_POST มา echo ก็ออกนะครับ
Date :
2013-06-10 22:47:12
By :
cmsarin
มันบันทึกใน DB เป็นค่า ว่างหรอครับ หรือไม่เข้าเลย ??
Date :
2013-06-10 22:48:05
By :
champkung226
แป่ว
ประวัติการแก้ไข 2013-06-10 22:51:04
Date :
2013-06-10 22:50:16
By :
champkung226
.= ไม่ใช่ .
Code (PHP)
$sql_insert = "INSERT INTO pc";
$sql_insert."(OldAsset,NewAsset,TCB,MAC,Serial,Brand,Model,HDD,RAM,CPUBrand,CPUSeries)"; // .=
$sql_insert."(CPUSpeed,IPAddress,Subnet,Gateway,SW,OS,Remark,Floor,CODE,Point,Role)";
$sql_insert."values('$txt_old','$txt_new','$txt_tcb','$txt_mac','$txt_s','$brand','$model','$txt_hdd')";
$sql_insert."('$txt_ram','$cpubrand','$txt_cpus','$txt_cpusp','$txt_address','$txt_subnet','$txt_gateway','$txt_sw','$os','$txt_remark')";
$sql_insert."('$txt_floor','$txt_code','$txt_point','$role')";
Date :
2013-06-10 22:53:38
By :
randOmizE
$sqlquery = mysql_db_query($dbname,$sql_insert) or die ("Error Query [".$sql_insert."]"); <<< เอา error ให้ดูหน่อยครับ
Date :
2013-06-10 22:53:57
By :
champkung226
Error Query [INSERT INTO pc(OldAsset,NewAsset,TCB,MAC,Serial,Brand,Model,HDD,RAM,CPUBrand,CPUSeries)(CPUSpeed,IPAddress,Subnet,Gateway,SW,OS,Remark,Floor,CODE,Point,Role)values('123456789','1234','11112','3321','4232','Dell','7303','423')('323','Intel','4444','221','','445','322','2321','Windows XP Service Pack 3','4232')('11','33','112','BMO')]
Date :
2013-06-10 23:10:49
By :
cmsarin
ก็คุณใช้ . (จุด) ในการต่อสตริง ที่จริงต้องใช้ .=
Code (PHP)
$sql_insert = "INSERT INTO pc";
$sql_insert."(OldAsset,NewAsset,TCB,MAC,Serial,Brand,Model,HDD,RAM,CPUBrand,CPUSeries)"; // ผิดตรงนี้ไปไง .=
$sql_insert."(CPUSpeed,IPAddress,Subnet,Gateway,SW,OS,Remark,Floor,CODE,Point,Role)";
$sql_insert."values('$txt_old','$txt_new','$txt_tcb','$txt_mac','$txt_s','$brand','$model','$txt_hdd')";
$sql_insert."('$txt_ram','$cpubrand','$txt_cpus','$txt_cpusp','$txt_address','$txt_subnet','$txt_gateway','$txt_sw','$os','$txt_remark')";
$sql_insert."('$txt_floor','$txt_code','$txt_point','$role')";
Date :
2013-06-10 23:13:21
By :
randOmizE
Load balance : Server 02