Witam wszystkich.
Mam problem z połączeniem bazy danych z moją aplikacją na androida. Jeżeli chodzi o korzystanie z sql'a jestem nowicjuszem dlatego też piszę z prośbą o pomoc ;).
Napisałem prosty kod w php który miał mi dać możliwość połączenia się z moją bazą danych w celu rejestracji i logowania użytkownika. jak przy jednym i drugim pliku php wyskakują błędy, których nie rozumiem.
KOD PHP REJESTRACJI:
<?php
$con = mysqli_connect("my_host", "my_user", "my_password", "my_db");
$name = $_POST["name"];
$surname = $_POST["surname"];
$username = $_POST["username"];
$age = $_POST["age"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (name, surname, username, age, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $surname, $username, $age, $password);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] =true;
echo json_encode($response);
?>
BŁĘDY:
Notice: Undefined index: name in /storage/h2/761/565761/public_html/Register.php on line 5
Notice: Undefined index: surname in /storage/h2/761/565761/public_html/Register.php on line 6
Notice: Undefined index: username in /storage/h2/761/565761/public_html/Register.php on line 7
Notice: Undefined index: age in /storage/h2/761/565761/public_html/Register.php on line 8
Notice: Undefined index: password in /storage/h2/761/565761/public_html/Register.php on line 9
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /storage/h2/761/565761/public_html/Register.php on line 13
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /storage/h2/761/565761/public_html/Register.php on line 14
{"success":true}
KOD PHP LOGOWANIA
<?php
$con = mysqli_connect("localhost", "id565761_zbrozli, "greg0ri0", "id565761_inzynierka");
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $name, $age, $username, $password);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["name"] = $name;
$response["age"] = $age;
$response["username"] = $username;
$response["password"] = $password;
}
echo json_encode($response);
?>
BŁĘDY:
otice: Undefined index: username in /storage/h2/761/565761/public_html/Login.php on line 4
Notice: Undefined index: password in /storage/h2/761/565761/public_html/Login.php on line 5
Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in /storage/h2/761/565761/public_html/Login.php on line 12
{"success":false}
`
Z góry dziękuję za pomoc i przepraszam za forme :)