[請益] 新手技術上問題 關於資料傳遞

看板PHP作者 (???)時間13年前 (2012/11/12 23:17), 編輯推噓0(0011)
留言11則, 3人參與, 最新討論串1/2 (看更多)
小弟最近開始接觸php 想練習寫個聊天室 現在碰到一個問題想來請教一下 <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>sent</title> </head> <body> <script> function insertDB(){ <?php $meg = $_POST['megword']; $str2 = $_SESSION['name']; $sqlinsert = "INSERT INTO chat( nick, words ) VALUES( $str2, fde );"; echo "alert( '$meg' )"; // $result = mysql_query($sqlinsert) or die('MySQL query error'); ?> } </script> <form mothod = "post" > <input name="megwords" type="text" size="20" maxlength="20" /> <input name="sent" type="button" onclick="javascript:insertDB();" value="送出 " /> </form> </body> </html> 基本上這是聊天室中輸入訊息按傳送的頁面 按出傳送以後我想在這個頁面做新增到資料庫的處理 新增要送出的訊息跟使用者暱稱 使用者暱稱在前面已經用session存取了 可是這個要傳出的訊息我抓不到 怎麼弄好像都不對 想來請教一下各問板友 <input name="megwords" type="text" size="20" maxlength="20" /> 該死的這行看著他沒辦法囧rz -- ◢ ◢ ∕ |╴╴╱ ︱ 皮卡丘眉頭一皺 覺得事情並不單純...... ∣ | ∣ ㄟˇㄏ | /╲ | ㄧ..ㄧ | / / |○/ ︷ \ ○| ︳ / -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.43.61.11 ※ 編輯: terryone 來自: 114.43.61.11 (11/12 23:21)

11/12 23:21, , 1F
$_POST['megword'] 然後 input name="megwords" ????
11/12 23:21, 1F

11/12 23:22, , 2F
樓上是說在insertdb裡面使用POST[megwords]嗎?
11/12 23:22, 2F

11/12 23:22, , 3F
這我嘗試過了 抓不到
11/12 23:22, 3F

11/12 23:23, , 4F
你先print_r($_POST) 看看吧
11/12 23:23, 4F

11/12 23:25, , 5F
你input name是megwords 但卻抓$POST['megword']
11/12 23:25, 5F

11/12 23:28, , 6F
加上 你確定你的onclick的動作會POST資料出去嗎?
11/12 23:28, 6F

11/12 23:28, , 7F
眼殘@@ 不過改回POST[megwords] 一樣抓不到
11/12 23:28, 7F

11/12 23:29, , 8F
這也是我的疑問 我不知道這樣的情到底該怎麼抓資料
11/12 23:29, 8F

11/12 23:31, , 9F
google "form submit"
11/12 23:31, 9F

11/12 23:57, , 10F
mothod?改成method呢?
11/12 23:57, 10F

11/13 00:01, , 11F
改了一樣抓不到
11/13 00:01, 11F
我爬文的結果應該是button觸發javascript 會導致POST接不到東西 所以我改成 <form method = "post" action = "自己這一頁!!.php" > <input name="megwords" type="text" size="20" maxlength="20" /> <input name="sent" type="submit" value="送出 " /> ^^^^^^^ button改submit 就順利的接到東西了 上面的function直接拔掉function包覆的部分 直接<?php function內容 ?> 就都完成我的需求了 不知道我上面的理解有無錯誤的地方 請指正 ※ 編輯: terryone 來自: 114.43.61.11 (11/13 00:19) ※ 編輯: terryone 來自: 114.43.61.11 (11/13 00:20)
文章代碼(AID): #1GeHCIN0 (PHP)
文章代碼(AID): #1GeHCIN0 (PHP)