php ชี้แนะด้วยครับ insert แล้วไม่ยอม update ($_REQUEST)
ใช้คำสั่ง
Code
$id = $_REQUEST['id'];
แล้วมันไม่ยอมinsertลง database
Code
<? include "chksession.php"; ?>
<HTML>
<HEAD><TITLE>ฝากข้อความบนเว็บ </TITLE>
<SCRIPT language=JavaScript>
function add_text(x) {
document.frm.message.value = document.frm.elements.message.value+" "+ x;
document.frm.message.focus();
}
</SCRIPT>
</HEAD>
<BODY>
<H2>ฝากข้อความบนเว็บ</H2>
<FONT FACE="TAHOMA" SIZE="2">
<TABLE BORDER="2" BORDERCOLOR="#0080C0" WIDTH="210">
<TR>
<TD>
<FONT FACE="TAHOMA" SIZE="2">
<MARQUEE WIDTH="210" HEIGHT="250" DIRECTION="down"
ONMOUSEOVER=stop(); ONMOUSEOUT=start();
SCROLLAMOUNT="1" SCROLLDELAY="0">
<?
include "connect.php";
include "function.php";
$id = $_REQUEST['id'];
$sql = "SELECT L.id,L.username,R.user_id,R.chat_id,R.message,R.save_date
FROM tb_member L LEFT JOIN tb_message R
ON L.id = R.user_id
where R.chat_id = $id";
$result=mysql_db_query($dbname,$sql) ;
if (empty($result) ) { //ดักerror
echo "มีปัญหาตรง mysql_db_query";
}
while ($record=mysql_fetch_array($result) ) {
$idm=$record[idm];
$user_id=$record[user_id];
$chat_id=$record[chat_id];
$message=nl2br($record[message]);
$save_date=$record[save_date];
$save_date=displaydate_time($save_date);
$pic="<IMG SRC='images/smile.gif'>";
$message=str_replace(":)",$pic, $message);
$pic="<IMG SRC='images/open_mouthed_smile.gif'>";
$message=str_replace(":D",$pic, $message);
$pic="<IMG SRC='images/winking_smile.gif'>";
$message=str_replace(";)",$pic, $message);
$pic="<IMG SRC='images/sursprised_smile.gif'>";
$message=str_replace(":-O",$pic, $message);
$pic="<IMG SRC='images/smile_with_tongue_out.gif'>";
$message=str_replace(":P",$pic, $message);
$pic="<IMG SRC='images/hot_smile.gif'>";
$message=str_replace("(H)",$pic, $message);
$pic="<IMG SRC='images/angry_smile.gif'>";
$message=str_replace(":@",$pic, $message);
$pic="<IMG SRC='images/confused_smile.gif'>";
$message=str_replace(":S",$pic, $message);
$pic="<IMG SRC='images/embarrassed_smile.gif'>";
$message=str_replace(":$",$pic, $message);
$pic="<IMG SRC='images/sad_smile.gif'>";
$message=str_replace(":(",$pic, $message);
echo "<BR>$message<BR>";
echo "<B>จาก : </B>$sess_username<BR>";
echo "<B>วัน : </B>$save_date <br>";
echo "----------------------------------------<BR>";
} // while
echo mysql_error();
?>
</MARQUEE>
</FONT>
</TD>
</TR>
</TABLE>
<FORM METHOD="post" NAME="frm" ACTION="save.php?id=<?=$id?>" ONSUBMIT="return check_data()">
ชื่อ : <b><?=$sess_username?></b><BR>
ฝากข้อความ : <BR>
<TEXTAREA NAME="message" ROWS="3" COLS="33"></TEXTAREA><BR>
<A HREF="javascript:add_text(':)')"><IMG SRC="images/smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(':D')"><IMG SRC="images/open_mouthed_smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(';)')"><IMG SRC="images/winking_smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(':-O')"><IMG SRC="images/sursprised_smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(':P')"><IMG SRC="images/smile_with_tongue_out.gif" BORDER="0"></A>
<A HREF="javascript:add_text('(H)')"><IMG SRC="images/hot_smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(':@')"><IMG SRC="images/angry_smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(':S')"><IMG SRC="images/confused_smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(':$')"><IMG SRC="images/embarrassed_smile.gif" BORDER="0"></A>
<A HREF="javascript:add_text(':(')"><IMG SRC="images/sad_smile.gif" BORDER="0"></A>
<BR>
<INPUT TYPE="submit" VALUE="Submit">
<INPUT TYPE="reset" VALUE="Reset"> </form>
<FORM METHOD="POST" NAME="frm2" ACTION="../member/logout.php" >
<input type="submit" value="Login" >
</FORM>
</FONT>
</BODY>
</HTML>
Code save
<?php
$message=$_POST[message];
$id = $_REQUEST['id'];
if ( $message=="") {
echo "<h3><a href='../message/message.php?id=$id'>ERROR : กรุณากรอกข้อมูลให้ครบด้วยครับ</a></h3>";
exit();
}
include "connect.php";
$save_date=date("Y-m-d H:i:s");
$sql="insert into tb_message values('','$user_id','$chat_id','$message','$save_date') ";
$result=mysql_db_query($dbname,$sql);
if ($result) {
header("Location: ../message/message.php?id=$id");
} else {
echo "<h3>ERROR : ไม่สามารถบันทึกข้อมูลได้</h3>";
}
mysql_close();
?>
จากในรูปมันไม่ยอมอัพเดทฟิลด์ chat_id กับ user_id คือมีค่าเป็น0
ส่วนที่มีค่าเป็นเลขอื่นผมต้องแก้ไขจากในดาต้าเบสเองTag : PHP
ประวัติการแก้ไข 2011-12-19 11:20:20
Date :
2011-12-19 11:02:10
By :
matay107
View :
1167
Reply :
3
echo $sql; ดูครับ
Date :
2011-12-19 11:45:19
By :
Dragons_first
แก้ได้แล้วครับ เพิ่ม
$user_id = $_REQUEST['user_id'];
$chat_id = $_REQUEST['chat_id'];
ลงไป
Date :
2011-12-20 09:48:25
By :
matay107
Load balance : Server 02