PHP POST上傳,無法讀取上傳的字串
本地c#寫的 用WebClient類http://1.liuruitao.sinaapp.com/test.php?name={0}通過這個url上傳的,網頁那邊
if($_SERVER['REQUEST_METHOD']=="POST")
{
// $s=json_encode($_post)
$s=$_GET["name"];
echo "hello world!!";
echo $_POST["name"];
$conn=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);
if(!$conn)
die("connect fail".mysql_error());
mysql_select_db('app_liuruitao',$conn);
$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
mysql_query($sql,$conn);//借SQL語句插入資料
mysql_close();//關閉MySQL串連
echo "insert success";
}
就是無法正確擷取上傳的name裡面的字串插入到資料庫中,大家幫幫忙謝謝了
------解決方案--------------------
$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
如果 $s 無值,那麼實際執行的 SQL指令為
insert into 表名 values ('3344556677',,3,'4',5,'6','7','8','9')
顯然是錯誤的
可通過
mysql_query($sql,$conn) or die(mysql_error());
知道這種情況是否存在
另外
$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
應寫作
$sql = "insert into $db values ('3344556677','$s',3,'4',5,'6','7','8','9')";
以免意外的發生