2017-02-17 123 views
-1

我在做項目,它需要android-PHP-MySQL連接。 我編程的PHP代碼,但它不起作用。錯誤代碼說'未定義的索引:userId ...' 我不知道如何解決它。我搜索了一些解決方案,但我找不到正確的答案。其他Android項目的其他PHP代碼正在工作。爲什麼..?PHP錯誤 - 未定義索引:userId

以下是我的PHP代碼。

<?php 
error_reporting(E_ALL); 
ini_set("display_errors", 1); 

require "init.php"; 

$userId = $_POST["userId"]; 
$username = $_POST["username"]; 
$userphone = $_POST["userphone"]; 
$usermail = $_POST["usermail"]; 
$userpw = $_POST["userpw"];  

$sql = "INSERT INTO register_info VALUES ('$userId', '$username', '$userphone', '$usermail', '$userpw');"; 
if(mysqli_query($con, $sql)) 
{ 
    var_dump($userId,$username,$userphone,$usermail, $userpw); 
} 

?> 

這就是錯誤代碼。

Notice: Undefined index: userId in /var/www/html/website/web/webapp/insertUser.php on line 9 

Notice: Undefined index: username in /var/www/html/website/web/webapp/insertUser.php on line 10 

Notice: Undefined index: userphone in /var/www/html/website/web/webapp/insertUser.php on line 11 

Notice: Undefined index: usermail in /var/www/html/website/web/webapp/insertUser.php on line 12 

Notice: Undefined index: userpw in /var/www/html/website/web/webapp/insertUser.php on line 13 
string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" 
+0

您身在何處插入查詢出欄值??? – Sona

+0

你甚至正在發佈POST請求/發佈表單嗎?如果是這樣,那麼表單是什麼樣的?和SQL注入。 – jeroen

+0

要麼你沒有發佈數據,或者你沒有給你的名字/值對使用你的'$ _POST'數組名稱 – RiggsFolly

回答

-1

查詢mysql有解決方法。

嘗試

$sql = "INSERT INTO register_info (userId, username, userphone, usermail, userpw) VALUES ('$userId', '$username', '$userphone', '$usermail', '$userpw');"; 

或看到

https://www.w3schools.com/php/php_mysql_insert.asp

+0

我嘗試了你寫的,但結果是一樣的 –