รบกวนดูโค๊ดให้อีกรอบครับ

เริ่มโดย tongchimlang, 22 กันยายน 2011, 14:03:38

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

tongchimlang

ขอบคุณมากนะครับสำหรับคำตอบหน้าก่อนนี้
** เจอปัญหาอีกแล้ว
คือผม ได้ submit ที่หน้า ตอบกระทู้ สามารถ Insert คำตอบได้
แต่ปัญหา พอ submit เสร็จมันจะต้อง โชว์หัวข้อกระทู้และตามด้วยคำตอบของแต่ละคน
ใช่ไหมครับ แต่นี้มันกับไม่ยอมโชว์ หัวข้อของกระทู้ที่เราเข้าไปตอบ
มันโชว์เฉพาะคำตอบของแตะละคนอะครับ ผมเลยอยากให้ดูโค๊ดให้อีกครังครับ

<?
  include "connect.php";
  include "function1.php";
 
$ddd=$_POST[submit];
if(trim($ddd)=="บันทึก"){
$sql="select  *   from tanswer   where  adate='".trim($_POST['adate'])."' and atime='".trim($_POST['atime'])."' and qid=".trim($_POST['qid'])." ";
$result=mysql_query($sql);
$numr=mysql_num_rows($result);
if($numr==0){                       
$sql="  INSERT INTO tanswer(qid,apost,adetail,adate,aip,atime)
      VALUES
(".trim($_POST['qid']).",'".trim($_POST['apost'])."' ,'".trim($_POST['adetail'])."','".trim($_POST['adate'])."','".trim($_POST['aip'])."','".trim($_POST['atime'])."')";
mysql_query($sql);     
            }
         
            }
?>

<?
$sql = "select * from tquestion where qid ='".trim($_GET['qid'])."' ";
$re=mysql_query($sql);
$row=mysql_fetch_array($re);
$qid=$row["qid"];
?>
<table width="80%"    align="center">
  <tr>
  <td>หัวข้อกระทู้> <? echo $row["qname"]?></td>
  </tr>
   <tr>
      <td ><? echo $row['qdetail']?></td>
   </tr>
   <tr>
      <td <? echo $row['qpost']?></td>
   </tr>

</table>
               

<?
$sql="select * from tanswer  where qid ='".trim($_POST['qid'])."' Order by adate,atime ";
$re=mysql_query($sql);
while ($row=mysql_fetch_array($re)){
?>
<table width="80%"   align="center">
        <tr>
          <td >คำตอบจาก : <? echo $row["apost"]?>
               </tr>
      <tr>
      <td> <? echo $row['adetail']?></td>
      </tr>
</table>

<?
}
?>

<form action="detail.php" method="post">
<table width="67%"  border="0" align="center">
<tr>
<td width="52%">รายละเอียด</td>
<td width="48%"><textarea name="adetail" cols="40" rows="4"></textarea></td>
</tr>
<tr>
<td>ชื่อ / E - Mail ผู้แสดงความคิดเห็น</td>
<td><input name="apost" type="text" size="40"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="      บันทึก      ">
</td>
</tr>
<input type="hidden" name="adate" value="<? echo date('Y')."-".date('m')."-".date('d')?>">
<input type="hidden" name="atime" value="<? echo date('H:i:s')?>">
<input type="hidden" name="aip" value="<? echo $REMOTE_ADDR?>">
<input type="hidden" name="qid" value="<? echo $qid ?>">
</table>
</form>

รบกวนอีกครั้งครับ
ขอบคุณครับ
[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

kitazawa1st

พอ submit แล้วค่า $_GET['qid'] มันหายครับ

แก้ที่ form

<form action="detail.php<?php echo $_GET['qid']; ?>" method="post">
เล็กสั้น ขยันซอย

tongchimlang

#2
<form action="detail.php<?php echo $_GET['qid']; ?>" method="post">
**ทำแล้วยังไม่ได้เลยครับ**
ใช่แล้วครับ พอ submit แล้วค่า qid หาย มันจึงไม่รู้จะไป
selec where เท่ากับค่า qid ตัวไหน
แต่มัน Insert ลงในฐานข้อมูล ผมดูที่ค่า qid ก็ตรงนะครับ
ค่า qid ที่ส่งมาจากหน้า post.php
<a href="javascript:new_window('detail.php?qid=<? echo $row["qid"]?>')"><? echo $row["qname"]?></a>


แต่ถ้าในเครื่องคอม ไม่ต้องใช้ $_GET หรือ $_POST มารับค่า
มันสามารถทำงานได้หมดไม่มีปัญหา
พอ Up ขึ้น Host แล้วมันไม่ยอมส่งค่า ก็เลยต้องมาใช้  $_GET หรือ $_POST
ก็เลยต้องมาไล่หาค่า qid

***นี้คือโค๊ดที่ใช้ select หัวข้อกระทู้มาโชว์
<?
//$sql = "select * from tquestion where qid ='".$qid."' ";  //บรรทัดนี้ในคอม จะสามารถทำงานได้หมด โชว์หัวข้อกระทู้ พร้อม คำตอบ ขอคนที่ submit ได้
$sql = "select * from tquestion where qid ='".trim($_GET['qid'])."' "; //บรรทัดนี้บน Host ลิ้งจากหน้ารวมกระทู้มาโชว์หน้า detail.php ได้
//แต่เวลามีคนเข้ามาตอบ พอ submit เสร็จมันจะ INsert ลงฐานข้อมูล แต่มันจะไม่โชว์ห้วข้อกระทู้ และคำตอบนั้น
$re=mysql_query($sql);
$row=mysql_fetch_array($re);
?>

***นี้คือโค๊ดที่ใช้ select คำตอบกระทู้มาโชว์
<?
$sql="select * from tanswer  where qid ='".trim($_GET['qid'])."' Order by adate,atime ";ใช้ตัวนี้ Host ทำงานได้
//$sql="select * from tanswer  where qid ='".$qid."' Order by adate,atime ";ใช้ตัวนี้คอมทำงานได้
$re=mysql_query($sql);
while ($row=mysql_fetch_array($re)){
?>

รบกวนด้วยครับ

ปล.ผมใช้ Host Free ครับ
[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

tongchimlang

[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

kitazawa1st

#4
ที่เดิมแหละครับ ผมลืมใส่เครื่องหมายคำถามให้ "?" ขอโทษด้วยคร๊าฟฟฟ

<form action="detail.php?<?php echo $_GET['qid']; ?>" method="post">
เล็กสั้น ขยันซอย

p44n

ตรวจสอบ
-ค่า id ที่ จะ select มีจิงมั้ย
-ผลของการ query มีจิงมั้ย

ตอนแสดงผล
-ใช้ตัวแปรถูกต้องมั้ย

ถ้าถูกต้องมันก้อต้องแสดงข้อมูลครับ ยกเว้นข้อมูลไม่มีจิง

ปล.ผมเข้าใจว่าคุณแอดข้อมูลได้ไม่มีปัญหาใช่มั้ยครับ
Python, PHP OOP, MVC CodeIgniter, MongoDB, MySQL, MsSQL ,CSS Tableless, Responsive Design, Cross-platform, Javascript, jQuery, AngularJS, NodeJS,  Fackbook API, Paypal API, Omise API, Google Map API, C# Window Applications, .NET Framework, JAVA (Android Developer, JSP), Hybrid Application with Cordova + Ionic Framework, ReactJS, React Native

omegarism

<?
$sql = "select * from tquestion where qid ='".trim($_GET['qid'])."' ";
$re=mysql_query($sql);
$row=mysql_fetch_array($re);
$qid=$row["qid"];
?>

ในส่วนนี้แก้เป็นอย่างนี้น่ะครับ

<?
$sql = "select * from tquestion where qid ='".trim($_POST['qid'])."' ";
$re=mysql_query($sql);
$row=mysql_fetch_array($re);
$qid=$row["qid"];
?>

ลองดูครับ
รับทำเว็บ ==> [direct=http://www.intrendwebsite.com]IntrendWebsite.com[/direct]

tongchimlang

อ้างถึงจาก: kitazawa1st ใน 23 กันยายน 2011, 14:38:26
ที่เดิมแหละครับ ผมลืมใส่เครื่องหมายคำถามให้ "?" ขอโทษด้วยคร๊าฟฟฟ

<form action="detail.php?<?php echo $_GET['qid']; ?>" method="post">

ผลลองใส่ code ตามที่แนะนำแล้ว
ผลปรากฎว่ามันไม่โชว์ตั้งแต่แรกเลยครับ คือตั้งแต่ง ลิ้งมา
จากหน้า post.php มันไม่ส่งค่ามาเลย
[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

thai2ads

<input type="hidden" name="qid" value="<? echo trim($_POST['qid']); ?>">

รับทำเว็บไซต์ เขียนระบบต่างๆตามที่ต้องการ
รับทำเว็บไซต์ | ทองคำราคาวันนี้

p44n

ถ้าไม่มีการส่งค่า id มา

การรับค่า
-การรับค่าถูกต้องมั้ย

การส่งค่า
-ส่ง id มาจากหน้าไหน
-รูปแบบการส่งถูกต้องหรือป่าว
-id ที่จะส่งมีจิงมั้ย

ทดสอบการรับและส่ง ด้วยการ test ดูครับ

ปล.รันบน host จำเป็นต้อง $_post $_get ถูกต้องแล้วครับ จิงๆแล้ว รันที่เครื่อง ก้อให้ทำเป็นนิสัยไปเลย
Python, PHP OOP, MVC CodeIgniter, MongoDB, MySQL, MsSQL ,CSS Tableless, Responsive Design, Cross-platform, Javascript, jQuery, AngularJS, NodeJS,  Fackbook API, Paypal API, Omise API, Google Map API, C# Window Applications, .NET Framework, JAVA (Android Developer, JSP), Hybrid Application with Cordova + Ionic Framework, ReactJS, React Native

tongchimlang

<?
$sql = "select * from tquestion where qid ='".trim($_POST['qid'])."' ";
$re=mysql_query($sql);
$row=mysql_fetch_array($re);
$qid=$row["qid"];
?>
ผมแก้เป็น qid ='".trim($_GET['qid'])."' ";แล้วครับ
ก็ยังเหมือเดิม  
ผมสามารถ Insert ข้อมูลได้ไม่มีปัญหา ค่า qid ที่ Insert ก็ตรงตามเลขที่กระทู้
ผมนั้งไล่หา  Code มาสองวันแล้วยังทำไม่ได้เลยครับ ผมคิดว่า
บรรทัดที่ $sql = "select * from tquestion where qid ='".trim($_GET['qid'])."' ";
ก่อนจะ submit มันยังมีค่า qid อยู่ แต่หลังจาก submit เสร็จ ค่า qid ไม่มีก็เลย
select มาโชว์ตามเงื่อนไข qid ไม่ได้
เครียดมาก
ช่วยหน่อยนะครับ

[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

p44n

หลัง submit เสร็จ คุณอาจจะต้องส่งค่า id อีกรอบ

$sql="insert yyyyyyyyyyy";
$re=mysql_query($sql);

if($re){
print "detail.php?id=xxxx";// redirect ไป detail.php?id=xxxx เอานะครับ
}
Python, PHP OOP, MVC CodeIgniter, MongoDB, MySQL, MsSQL ,CSS Tableless, Responsive Design, Cross-platform, Javascript, jQuery, AngularJS, NodeJS,  Fackbook API, Paypal API, Omise API, Google Map API, C# Window Applications, .NET Framework, JAVA (Android Developer, JSP), Hybrid Application with Cordova + Ionic Framework, ReactJS, React Native

thai2ads

มีโปรแกรม TeamViewer เปล่าเดียวดูให้ ตอนนี้กำลังว่างจากงานบริษัท เดียวช่วยดูให้ครับ
รับทำเว็บไซต์ เขียนระบบต่างๆตามที่ต้องการ
รับทำเว็บไซต์ | ทองคำราคาวันนี้

tongchimlang

อ้างถึงจาก: thai2ads ใน 23 กันยายน 2011, 15:25:29
<input type="hidden" name="qid" value="<? echo trim($_POST['qid']); ?>">


ผมแก้แล้วครับ พอ Submit Insert ลงฐานข้อมูล
ค่า qid จะเป็น 0 ครับจะไม่ตรงตามค่า qid ของกระทู้ครับ
[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

tongchimlang

อ้างถึงจาก: thai2ads ใน 23 กันยายน 2011, 15:44:37
มีโปรแกรม TeamViewer เปล่าเดียวดูให้ ตอนนี้กำลังว่างจากงานบริษัท เดียวช่วยดูให้ครับ

มีครับ  เริ่มกันเลยไหมครับ
[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

seowizard

วิธีการ debug นะครับ ดูที่ไฟล์แรกก่อน โดยการ echo ค่ามาดู เช่น

อ้างถึง<?php
echo "date = ".date('Y')."-".date('m')."-".date('d');
echo "<br>time = ".date('H:i:s');
echo "<br>remote address = ".$REMOTE_ADDR
echo "<br>qid = ".$qid

?>
<input type="hidden" name="adate" value="<? echo date('Y')."-".date('m')."-".date('d')?>">
<input type="hidden" name="atime" value="<? echo date('H:i:s')?>">
<input type="hidden" name="aip" value="<? echo $REMOTE_ADDR?>">
<input type="hidden" name="qid" value="<? echo $qid ?>">

ดูว่าค่ามีครบไหมก่อนที่จะทำการ submit form
แล้วถ้าดูว่า form ส่งไปเป็น method อะไร post หรือ get

อ้างถึง<form action="detail.php" method="post">

ถ้าส่งเป็น post  เวลารับค่า  ก็ใช้  $_POST[qid]
ถ้าส่งเป็น get เวลารับค่า ก็ใช้ $_GET[qid]
แล้วก็ทำการ echo ค่ามาดูด้วยว่ามาไหม

thai2ads

อ้างถึงจาก: tongchimlang ใน 23 กันยายน 2011, 15:50:17
อ้างถึงจาก: thai2ads ใน 23 กันยายน 2011, 15:44:37
มีโปรแกรม TeamViewer เปล่าเดียวดูให้ ตอนนี้กำลังว่างจากงานบริษัท เดียวช่วยดูให้ครับ

มีครับ  เริ่มกันเลยไหมครับ

ได้ครับ pm รหัสมาละกันนะครับเปิดหน้าที่เกี่ยวข้องไว้ด้วยนะ
รับทำเว็บไซต์ เขียนระบบต่างๆตามที่ต้องการ
รับทำเว็บไซต์ | ทองคำราคาวันนี้

tongchimlang

#17

(ได้แล้วครับ)
ขอบคุณสำหรับคำแนะนำทุกๆคนนะครับ
และขอบคุณมาก สำหรับคุณ thai2ads
ที่ช่วยแก้โค๊ดให้ ขอบคุณในน้ำใจมากๆ ครับ

**ที่ผิดคือ**ผิดนิดเดียว
<form action="detail.php?<?php echo $_GET['qid']; ?>" method="post">

ที่ถูกคือ
<form action="detail.php?qid=<?php echo $_GET['qid']; ?>" method="post">
[direct=http://siripathfarm.mine.nu]ปั้มออกซิเจน[/direct]
[direct=http://siripathfarm.mine.nu]ปั๊มออกซิเจน12v[/direct]
[direct=http://www.facebook.com/siripathfarm]ปั๊มออกซิเจนพกพา[/direct]
[direct=http://siripathfarm.mine.nu]หัวอ๊อก[/direct]
[direct=http://www.facebook.com/siripathfarm]กุ้งก้ามแดง[/direct]

thai2ads

โทษทีเมื่อกี้นี้ไปไม่ได้บอกก่อน พอดีมีงานด่วนเข้าบริษัทเลยต้องคุยงานกับพี่เขายาวเลย ^ ^
ตกลงได้แล้วนะครับ เส้นผมบังภูเขาจริงๆ  :wanwan012:
รับทำเว็บไซต์ เขียนระบบต่างๆตามที่ต้องการ
รับทำเว็บไซต์ | ทองคำราคาวันนี้

kitazawa1st

อ้างถึงจาก: tongchimlang ใน 23 กันยายน 2011, 16:56:58

(ได้แล้วครับ)
ขอบคุณสำหรับคำแนะนำทุกๆคนนะครับ
และขอบคุณมาก สำหรับคุณ thai2ads
ที่ช่วยแก้โค๊ดให้ ขอบคุณในน้ำใจมากๆ ครับ

**ที่ผิดคือ**ผิดนิดเดียว
<form action="detail.php?<?php echo $_GET['qid']; ?>" method="post">

ที่ถูกคือ
<form action="detail.php?qid=<?php echo $_GET['qid']; ?>" method="post">

เหอๆ ที่เดียวกัน ลืมใส่ตัวแปร  :wanwan004: :wanwan004: :wanwan004:
เล็กสั้น ขยันซอย