Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fetching user from Sqlite: {Student_ID=222002, Parent_Name=muha, Parent_ID=1110044, Student_Name=Sameer, MyImage=MS5qcGc=, Username=muhaa}
- // Fetching user details from SQLite
- HashMap<String, String> user = db.getUserDetails();
- String Parent_Name = user.get("Parent_Name");
- String Username = user.get("Username");
- String Parent_ID = user.get("Parent_ID");
- String MyImage = user.get("MyImage");
- String Student_ID = user.get("Student_ID");
- String Student_Name = user.get("Student_Name");
- txtParent_Name.setText(Parent_Name);
- txtUsername.setText(Student_ID);
- txtParent_ID.setText(Student_Name);
- /* as i searched and found out this is what should i do to display the image but it doesnt work
- SkImageDecoder::Factory returned null
- */
- byte[] imageAsBytes = Base64.decode(MyImage.getBytes(), Base64.DEFAULT);
- pic.setImageBitmap(
- BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
- );
- <?php
- ini_set('display_errors', 1);
- error_reporting(~0);
- if (isset($_POST['Parent_ID']) && isset($_POST['Parent_Name']) && isset($_POST['Username'])&& isset($_POST['password'])&& isset($_FILES['photo']['name'])) {
- $Parent_ID = $_POST['Parent_ID'];
- $Parent_Name = $_POST['Parent_Name'];
- $Username = $_POST['Username'];
- $password = $_POST['password'];
- // This is the directory where images will be saved
- $target = "images/";
- $target = $target . basename( $_FILES['photo']['name']);
- $pic=($_FILES['photo']['name']);
- $base64 =base64_encode($pic);
- $serverName = "HP-PC";
- $userName = "sa";
- $userPassword = 'P@ssw0rd';
- $dbName = "Attendance";
- $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
- $conn = sqlsrv_connect( $serverName, $connectionInfo);
- if( $conn === false ) {
- die( print_r( sqlsrv_errors(), true));
- }
- $sql = "INSERT INTO Parents(Parent_ID, Parent_Name, Username, Password, MyImage) VALUES(?, ?, ?, ?, '$base64')";
- $params = array($_POST['Parent_ID'], $_POST['Parent_Name'], $_POST['Username'], $_POST['password'],$base64);
- $stmt = sqlsrv_query( $conn, $sql, $params);
- if( $stmt === false ) {
- die( print_r( sqlsrv_errors(), true));
- }else{
- echo "Record add successfully";
- }
- sqlsrv_close($conn);}
- // Writes the photo to the server
- if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
- {
- // Tells you if its all ok
- echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
- }
- else {
- // Gives and error if its not
- echo "Sorry, there was a problem uploading your file.";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement