|
 |
|
รบกวนช่วยเช็คโค้ดนี้ให้หน่อยค่ะ เกี่ยวกับการ php และการ update ค่าใน ฐานข้อมูล |
|
 |
|
|
 |
 |
|
ลองเอา $_SESSION ใส่ในตัวแปรสักตัวเช่น $x
แล้ว "WHERE username = ' ".$x." ' " ดูครับ ผมว่าน่าจะได้นะ
*** ' " อาจต้องติดกันนะครับ ผมเว้นไว้ให้ดูจะได้เห็นชัดๆ ***
|
ประวัติการแก้ไข 2011-04-06 22:30:15
 |
 |
 |
 |
Date :
2011-04-06 22:29:32 |
By :
bank32 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำตามที่บอกเเล้วค่ะ ตอนนี้ update คะเเนนได้เเล้ีว เเต่คะเเนนเก่ายังไม่ถูกเก็บใน previous_score อ่ะค่ะ
และก็มี error ตรง error4 ด้วยอ่ะค่ะ
รบกวนอีกนิดนะคะ
Code (PHP)
<?php
session_start();
// test
$_SESSION['username'] = "pat";
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "kinderkids";
$connection = mysql_connect($host, $user, $pass) or die ("cannot connect to DB");
$sql = mysql_select_db($dbname,$connection) or die ("Couldn't find db");
if (!$sql) {
die ("cannot select database");
}
print_r($_SESSION);
$s_username = $_SESSION['username'];
//$score = ($_REQUEST['varScore']);
$score = 75;
if ($score) {
$currentDate = date("Y-m-d");
$tbsql = "SELECT username FROM testscore2 where username = '".$s_username."'";
$result = mysql_query($tbsql)or die("error1");
$num_rows = mysql_num_rows($result);
if ($num_rows <> 0) {
while ($row = mysql_fetch_assoc($result))
{
$dbcurrent = $row['current_score'];
//$dbprevious = $row['previous_score'];
echo $dbcurrent;
}
$updateQuery = "UPDATE testscore2 SET previous_score = '{$dbcurrent}' WHERE username = '".$s_username."'";
//$updateQuery .= "WHERE username = '".$s_username."'";
mysql_query($updateQuery) or die("error2");
//$updatesql = "UPDATE testPreviousScore SET current_score = $score WHERE username = {$_SESSION['username']}";
$updatesql = "UPDATE testscore2 SET current_score = '{$score}'";
$updatesql .= "WHERE username = '".$s_username."'";
mysql_query($updatesql) or die("error3");
} else
$insertQuery = "INSERT INTO testscore2(username,last_visit, current_score) VALUES ('".$s_username."','$currentDate','$score')";
mysql_query($insertQuery) or die("error4");
} else
echo "no score posted";
?>
|
 |
 |
 |
 |
Date :
2011-04-07 01:00:39 |
By :
มะลิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$insertQuery = "INSERT INTO testscore2(username,last_visit, current_score) VALUES ('".$s_username."','$currentDate','$score')"
เปลี่ยนเป็น
$insertQuery = "INSERT INTO testscore2(username,last_visit, current_score) VALUES ('".$s_username."','".$currentDate."','".$score."')"
ก็น่าจะได้แล้วครับ $s_username ก็ใช้ถูกละนี่ครับ อีก 2 ตัวแปรหลังก็ใช้เหมือนกัน 
edit : พึ่งมาเห็นผมตอบช้าไป ป่านนี้คงได้แล้วแหละครับ ^^
|
ประวัติการแก้ไข 2011-04-08 20:22:12
 |
 |
 |
 |
Date :
2011-04-08 20:21:05 |
By :
bank32 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|