作者fatfattim (fattim)
看板PHP
標題[請益] 關於使用者輸入 格式問題
時間Sat Aug 9 17:30:46 2008
小弟我有爬過文了,只是還找不到正解,所以來問問各位大神
就是
<?php
echo "請輸入資料";
$name=$_GET['name'];
$id=$_GET['id'];
$Compiler=$_GET['Compiler'];
$Algorithm=$_GET['Algorithm'];
$comment=$_GET['comment'];
?>
<form action="add.php" method="get">
姓名 :<input type="text" name="name"><br>
學號 :<input type="text" name="id"><br>
Compiler數量 :<input type="text" name="Compiler"><br>
Algorithm數量:<input type="text" name="Algorithm"><br>
想說的話 :<input type="text" name="comment"><br>
<input type="submit" value="送出">
</form>
.......(省略一些應該是對的程式碼)
$sql="insert into OrderBook (學號,姓名,Compiler,Algorithm,comment) values
('123','陳狗庭',$Compiler,$Algorithm,$comment)";
這樣子可以新增
但是如果抓取 form 的 $name 及 $id(同樣輸入 '123','陳狗庭',只差在用$_GET所得到的值)
$sql="insert into OrderBook (學號,姓名,Compiler,Algorithm,comment) values
($id,$name,$Compiler,$Algorithm,$comment)";
便不能新增。
But!!!! 輸入 純數字 如 "123" "234" 都可以新增
真是太神奇了!!!
==========================
然後我用echo mb_detect_encoding($name) 去測我輸入的字串。
當我輸入中文 如"大寶" 顯示為 UTF-8
輸入 "dabao" 顯示為 ASCII
是編碼問題嗎? 但是瀏覽我select資料(包含中文)都不會出現亂碼?
請各位大神救救我~~ >.<...
==========================
環境 ubuntu 8.04
php + apache + sql + phpmyadmin (應該都是最新版,昨天才用 apt-get 抓的)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.168.138.4