SHARE
TWEET

Untitled

a guest Mar 20th, 2016 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Fetching user from Sqlite: {Student_ID=222002, Parent_Name=muha, Parent_ID=1110044, Student_Name=Sameer, MyImage=MS5qcGc=, Username=muhaa}
  2.    
  3. // Fetching user details from SQLite
  4.     HashMap<String, String> user = db.getUserDetails();
  5.  
  6.     String Parent_Name = user.get("Parent_Name");
  7.     String Username = user.get("Username");
  8.     String Parent_ID = user.get("Parent_ID");
  9.     String MyImage = user.get("MyImage");
  10.     String Student_ID = user.get("Student_ID");
  11.     String Student_Name = user.get("Student_Name");
  12.  
  13.     txtParent_Name.setText(Parent_Name);
  14.     txtUsername.setText(Student_ID);
  15.     txtParent_ID.setText(Student_Name);
  16.     /* as i searched and found out this is what should i do to display the image but it doesnt work
  17.     SkImageDecoder::Factory returned null
  18.     */
  19.     byte[] imageAsBytes = Base64.decode(MyImage.getBytes(), Base64.DEFAULT);
  20.     pic.setImageBitmap(
  21.             BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
  22.     );
  23.    
  24. <?php
  25. ini_set('display_errors', 1);
  26. error_reporting(~0);
  27. if (isset($_POST['Parent_ID']) && isset($_POST['Parent_Name']) && isset($_POST['Username'])&& isset($_POST['password'])&& isset($_FILES['photo']['name'])) {
  28. $Parent_ID = $_POST['Parent_ID'];
  29. $Parent_Name = $_POST['Parent_Name'];
  30. $Username = $_POST['Username'];
  31. $password = $_POST['password'];
  32.  
  33. // This is the directory where images will be saved
  34. $target = "images/";
  35. $target = $target . basename( $_FILES['photo']['name']);
  36. $pic=($_FILES['photo']['name']);
  37. $base64 =base64_encode($pic);
  38.  
  39. $serverName = "HP-PC";
  40. $userName = "sa";
  41. $userPassword = 'P@ssw0rd';
  42. $dbName = "Attendance";
  43. $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
  44. $conn = sqlsrv_connect( $serverName, $connectionInfo);
  45.  
  46. if( $conn === false ) {
  47. die( print_r( sqlsrv_errors(), true));
  48. }
  49. $sql = "INSERT INTO Parents(Parent_ID, Parent_Name, Username, Password, MyImage) VALUES(?, ?, ?, ?, '$base64')";
  50. $params = array($_POST['Parent_ID'], $_POST['Parent_Name'], $_POST['Username'], $_POST['password'],$base64);
  51. $stmt = sqlsrv_query( $conn, $sql, $params);
  52.  
  53. if( $stmt === false ) {
  54. die( print_r( sqlsrv_errors(), true));
  55. }else{
  56. echo "Record add successfully";
  57. }
  58.  
  59. sqlsrv_close($conn);}
  60. // Writes the photo to the server
  61. if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
  62. {
  63.  
  64. // Tells you if its all ok
  65. echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
  66. }
  67. else {
  68.  
  69. // Gives and error if its not
  70. echo "Sorry, there was a problem uploading your file.";
  71. }
  72. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top