Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Salam...

I Want to retrieve MYSQL phpmyadmin DB Data and Display it in Listview help of edittext.
Example:-
In DB I Have all Days Name Monday --- to Sunday & Some Colours Red --- to White.
In Android In Edittext When I Write Monday In ListView All Data are Shown Related to Monday
Just Like This its my php code.

connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$semester_class = $_GET['semester_class'];


$sql = "SELECT username FROM attendance_student WHERE semester_class='{$semester_class}'";
$result = mysqli_query($conn, $sql);

while(($row = mysqli_fetch_assoc($result)) == true){
   	$attendance_student[]=$row;
}
echo json_encode($attendance_student);


Please Help

What I have tried:

I Search Everywhere but can't find
Posted
Updated 25-Apr-20 13:12pm
v2

1 solution

For starters; your code is ripe for a vulnerability known as SQL Injection, which was identified well over 20 years ago...
NEVER EVER create an SQL command by string together together command text with user input- there is plenty of documentation on how to do add user content to a query
PHP
$stmt = $mysqli->prepare("SELECT username FROM attendance_student WHERE semester_class=?");
$stmt->bind_param("s", $_POST['name'], $semester_class);
$stmt->execute();
$result = $stmt->get_result();
References:
PHP: Prepared Statements - Manual[^]
PHP MySQLi Prepared Statements Tutorial to Prevent SQL Injection[^]
 
Share this answer
 
Comments
Member 14813260 26-Apr-20 6:50am    
In DB I Have all Days Name Monday --- to Sunday & Some Colours Red --- to White.
In Android In Edittext When I Write Monday In ListView All Data are Shown Related to Monday
Just Like This its my php code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900