|
|
|
แบบประเมิน เมื่อป้อนข้อมูลแล้วนำมาคำนวณ มันไม่เก็บผลรวมลงฐานข้อมูลด้วย ทำยังไงดีคะ |
|
|
|
|
|
|
|
สวัสดีค่ะ ทำแบบประเมิน เมื่อป้อนข้อมูลแล้วนำมาคำนวณ มันไม่เก็บผลรวมลงฐานข้อมูลด้วย เก็บเฉพาะค่าที่ป้อน ผลรวมเห็นเฉพาะหน้าเว็บ อยากให้เก็บลงฐานข้อมูลต้องทำยังไงคะ รบกวนด้วยนะคะ ขอบคุณค่ะ
Code (PHP)
<?php require_once('Connections/conn.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 business (bus_q1, bus_q2, bus_q3, bus_q4, bus_q5, bus_q6, bus_q7, bus_q8, bus_q9, bus_q10) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['bus_q1'], "int"),
GetSQLValueString($_POST['bus_q2'], "int"),
GetSQLValueString($_POST['bus_q3'], "int"),
GetSQLValueString($_POST['bus_q4'], "int"),
GetSQLValueString($_POST['bus_q5'], "int"),
GetSQLValueString($_POST['bus_q6'], "int"),
GetSQLValueString($_POST['bus_q7'], "int"),
GetSQLValueString($_POST['bus_q8'], "int"),
GetSQLValueString($_POST['bus_q9'], "int"),
GetSQLValueString($_POST['bus_q10'], "int"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "aa.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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p><center>???????????????????????</center></p>
<p> </p>
</form>
<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<center><table width="780" border="1">
<tr>
<td rowspan="2" align="center">???????</td>
<td colspan="5" align="center">???????????</td>
</tr>
<tr>
<td width="47" align="center">5</td>
<td width="44" align="center">4</td>
<td width="47" align="center">3</td>
<td width="41" align="center">2</td>
<td width="40" align="center">1</td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">1. ??????????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q1" value="5" /></td>
<td align="center"><input type="radio" name="bus_q1" value="4" /></td>
<td align="center"><input type="radio" name="bus_q1" value="3" /></td>
<td align="center"><input type="radio" name="bus_q1" value="2" /></td>
<td align="center"><input type="radio" name="bus_q1" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">2. ???????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q2" value="5" /></td>
<td align="center"><input type="radio" name="bus_q2" value="4" /></td>
<td align="center"><input type="radio" name="bus_q2" value="3" /></td>
<td align="center"><input type="radio" name="bus_q2" value="2" /></td>
<td align="center"><input type="radio" name="bus_q2" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">3. ????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q3" value="5" /></td>
<td align="center"><input type="radio" name="bus_q3" value="4" /></td>
<td align="center"><input type="radio" name="bus_q3" value="3" /></td>
<td align="center"><input type="radio" name="bus_q3" value="2" /></td>
<td align="center"><input type="radio" name="bus_q3" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">4. ??????????????????????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q4" value="5" /></td>
<td align="center"><input type="radio" name="bus_q4" value="4" /></td>
<td align="center"><input type="radio" name="bus_q4" value="3" /></td>
<td align="center"><input type="radio" name="bus_q4" value="2" /></td>
<td align="center"><input type="radio" name="bus_q4" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">5. ????????????????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q5" value="5" /></td>
<td align="center"><input type="radio" name="bus_q5" value="4" /></td>
<td align="center"><input type="radio" name="bus_q5" value="3" /></td>
<td align="center"><input type="radio" name="bus_q5" value="2" /></td>
<td align="center"><input type="radio" name="bus_q5" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">6. ????????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q6" value="5" /></td>
<td align="center"><input type="radio" name="bus_q6" value="4" /></td>
<td align="center"><input type="radio" name="bus_q6" value="3" /></td>
<td align="center"><input type="radio" name="bus_q6" value="2" /></td>
<td align="center"><input type="radio" name="bus_q6" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">7. ??????????????????????? / ???????????????</td>
<td align="center"><input type="radio" name="bus_q7" value="5" /></td>
<td align="center"><input type="radio" name="bus_q7" value="4" /></td>
<td align="center"><input type="radio" name="bus_q7" value="3" /></td>
<td align="center"><input type="radio" name="bus_q7" value="2" /></td>
<td align="center"><input type="radio" name="bus_q7" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">8. ????????????? / ?????????????????????? / ???????????????</td>
<td align="center"><input type="radio" name="bus_q8" value="5" /></td>
<td align="center"><input type="radio" name="bus_q8" value="4" /></td>
<td align="center"><input type="radio" name="bus_q8" value="3" /></td>
<td align="center"><input type="radio" name="bus_q8" value="2" /></td>
<td align="center"><input type="radio" name="bus_q8" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">9. ??????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q9" value="5" /></td>
<td align="center"><input type="radio" name="bus_q9" value="4" /></td>
<td align="center"><input type="radio" name="bus_q9" value="3" /></td>
<td align="center"><input type="radio" name="bus_q9" value="2" /></td>
<td align="center"><input type="radio" name="bus_q9" value="1" /></td>
</tr>
<tr>
<td align="left" valign="baseline" nowrap="nowrap">10.???????????????????????????????????????????????</td>
<td align="center"><input type="radio" name="bus_q10" value="5" /></td>
<td align="center"><input type="radio" name="bus_q10" value="4" /></td>
<td align="center"><input type="radio" name="bus_q10" value="3" /></td>
<td align="center"><input type="radio" name="bus_q10" value="2" /></td>
<td align="center"><input type="radio" name="bus_q10" value="1" /></td>
</tr>
<tr>
<td height="28" colspan="6" align="right" valign="baseline" nowrap="nowrap"><p>
<input type="submit" value="????????" />
</p></td>
</tr>
</table>
<p> </p>
</center>
<p>
<input type="hidden" name="MM_insert" value="form2" />
</p>
</form>
<p> </p>
</body>
</html>
อันนี้เป็นโค้ดคำนวณค่ะ
Code (PHP)
<?php
$host= 'localhost';
$user = 'root';
$pwd = '1234';
$db = 'test';
$conn = mysql_connect($host,$user,$pwd) or die (mysql_error());
mysql_select_db($db);
$sql = "SELECT * FROM business";
$query = mysql_query($sql);
$row = mysql_num_rows($query);
if($row > 0){
$bus_sum = array();
while($rs = mysql_fetch_array($query)){
$q1 = $rs['bus_q1'];
$q2 = $rs['bus_q2'];
$q3 = $rs['bus_q3'];
$q4 = $rs['bus_q4'];
$q5 = $rs['bus_q5'];
$q6 = $rs['bus_q6'];
$q7 = $rs['bus_q7'];
$q8 = $rs['bus_q8'];
$q9 = $rs['bus_q9'];
$q10 = $rs['bus_q10'];
$bus_sum[] = $q1+ $q2+ $q3+ $q4+ $q5+ $q6+ $q7+ $q8+ $q9+ $q10;
} // end while
print_r($bus_sum);
}else{
echo "Not Found.";
}
?>
Tag : PHP
|
ประวัติการแก้ไข 2012-09-17 16:02:33
|
|
|
|
|
Date :
2012-09-17 15:53:29 |
By :
gosling |
View :
1251 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เป็นไปได้ที่ชนิดข้อมูลมันเป็น float ไม่ใช่ int อย่างที่คุณ convert อ่ะคับ ลองดูดีๆ น่าจะเก็บเป็น text นะคับ ตอนที่ get ค่าอ่ะคับ
|
|
|
|
|
Date :
2012-09-17 16:22:27 |
By :
ichiko |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูแล้ว ก็ยังเหมือนเดิมค่ะ
|
|
|
|
|
Date :
2012-09-17 16:48:18 |
By :
gosling |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รู้แล้วค่ะว่าทำไม เพราะ array ไม่สามารถเก็บลงฐานข้อมูลได้ ..... ลองแปลงเป็น string แล้ว ก็ยังเป็นเหมือนเดิมค่ะ
ต้องทำยังไง ช่วยบอกด้วยนะคะ
|
|
|
|
|
Date :
2012-09-19 16:16:16 |
By :
gosling |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|