|
 |
|
ช่วยดูโค๊ดให้หน่อยคับ มันผิดตรงไหน ผมต้องแก้ตรงไหนบ้างคับ |
|
 |
|
|
 |
 |
|
ขอคำปรึกษาหน่อยครับ เกี่ยวการส่งค่า echo ไปpost ลงในดาต้าเบส
มีอยู่ว่าผมต้องการค่าล่าสุดจากดาต้าเบสตัวนึง ส่งไปยังอีกตัวนึง ผมมีดาต้าเบส2ตัว ชื่อ datastore และ weather
มีตารางที่เหมือนกัน
มี 4 ฟิวด์ time,temperature,pressure,humidity
ส่งค่าจาก weatheพ ไปยัง datastore มี3หน้าดังนี้ fetch_data.php,index.php,postdb.php
fetch_data.php
------------------------------------------------
<?php
$con=mysql_connect('localhost','root','1234');
mysql_select_db('ubu_weather');
$sql="SELECT *FROM `weather`WHERE`time`=(SELECT max(`time`)FROM `weather`)limit 0,1 ";
$last=mysql_query($sql);
echo mysql_error();
$last_row=mysql_fetch_array($last);
$time =$last_row['time'];
$temperature =$last_row['temperature'];
$pressure =$last_row['pressure'];
$humidity =$last_row['humidity'];
echo "time=$time&temperature=$temperature&pressure=$pressure&humidity=$humidity";
?>
---------------------------------------------
ส่งค่าไปยังหน้า postdb.php โดยควบคุมจากหน้า index.php
index.php
---------------------------------------------
<!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></title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var newdata;
$(document).ready(function(){
window.setInterval(fetchdata,1000*60);
});
function senddata(){
//window.location = 'http://www.uburesearch.com/ubu/postdb.php?'+newdata;
$.ajax({
type:'GET' ,
url:'postdb.php' ,
data:newdata,
success:function(v){
$(v).appendTo('#content');
}
});
}
function fetchdata(){
$.ajax({
type:'POST' ,
url:'fetch_data.php' ,
success:function(msg){
newdata = msg;
var pointer = '<span id="pr" style="color:#F00;"> <--</span>'
$('#pr').remove();
$('<p>sent - '+newdata+pointer+'</p>').prependTo('#content');
senddata();
}
});
}
</script>
<style>
#content{
margin:0 auto;
width:900px;
}
</style>
</head>
<div id="content"></div>
<body>
</body>
</html>
---------------------------------------------------------------
โดยมีหน้า postdb.php รับค่าจากหน้า fetch_data.php มาโพสต์ลงดาต้าเบสชื่อ datastore
postdb.php
---------------------------------------------------------------
<!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>
<?php
$time = $_POST['$time'];
$temperature = $_POST['$temperature'];
$pressure = $_POST['$pressure'];
$humidity = $_POST['$pressure'];
$con = mysql_connect('localhost','root','1234');
mysql_select_db('ubu_weather');
$sql ="INSERT INTO `ubu_weather`.`datastore` (`time`,`temperature`, `pressure`, `humidity`) VALUES ('$time', '$temperature', '$pressure', '$humidity')";
$result = mysql_query($sql);
if($result){
echo 'บันทึกข้อมูลสำเร็จ';
}else{
echo 'บันทึกข้อมูลไม่สำเร็จ';
}
?>
</body>
</html>
------------------------------------------------------------------
ปัญหาครับ ก็คือ มันแสดงค่า echo แต่มันไม่ส่งค่าไปยังดาต้าเบสชื่อ datastore
มันแสดงข้อความว่า
sent - time=2011-01-17 23:42:53&temperature=5&pressure=5&humidity=5 <--
บันทึกข้อมูลสำเร็จ
แล้วเช็คดูที่ดาต้าเบส
time temperature pressure humidity
0000-00-00 00:00:00 0 0 0
ขอความช่วยเหลือหน่อยนะคับ
ขอบคุณล่วงหน้าคับ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2011-01-19 21:29:04 |
By :
nu007 |
View :
723 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$sql ="INSERT INTO `ubu_weather`.`datastore` (`time`,`temperature`, `pressure`, `humidity`) VALUES ('$time', '$temperature', '$pressure', '$humidity')";
จุดมาจากไหนครับตรง insert into น่ะ ถ้าไม่ได้ลองเขียน query แยก insert ทีละ database ดูครับแต่เขียน Code ในหน้าเดียวกันลองดูครับโชคดี
|
 |
 |
 |
 |
Date :
2011-01-19 23:34:06 |
By :
gogo01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำทุกวิถีทางแล้วคับไม่ออกเลย
|
 |
 |
 |
 |
Date :
2011-01-19 23:43:29 |
By :
nu007 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วคับ
|
 |
 |
 |
 |
Date :
2011-01-26 12:30:40 |
By :
nu007 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|