-1

I'm doing project and it needs android-PHP-MySQL connection. I programmed PHP code, but it doesn't work. The error code says 'Undefined index: userId...' I don't know how to solve it. I googled for get some solutions but I couldn't find the right answer. Other PHP code with another android project is working. Why..?

Following is My PHP code.

<?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 );
}

?>

And this is the error code.

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) ""
Carly Yee
  • 45
  • 5
  • where you are giving column values in insert query??? – Soniya Basireddy Feb 17 '17 at 09:12
  • Are you even making a POST request / posting a form? If so, what does the form look like? And sql injection. – jeroen Feb 17 '17 at 09:12
  • Either you are not POSTing data or you are not giving your name/value pairs the names that you are using for your `$_POST` array names – RiggsFolly Feb 17 '17 at 09:19
  • Oh, I edited like this. But the result is same.. I edited $sql sentence as Nguyễn Trung Hiếu wrote, but it doesn't work. $userId = $_POST["userId"]; $username = $_POST["username"]; $userphone = $_POST["userphone"]; $usermail = $_POST["usermail"]; $userpw = $_POST["userpw"]; – Carly Yee Feb 17 '17 at 10:42

1 Answers1

-1

Query mysql have solution.

try

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

or see

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

Nguyễn Trung Hiếu
  • 2,004
  • 1
  • 10
  • 22