Saturday, 16 April 2016

Curious Room Databases Part Two


Curious Room Data Base Showing Tables
Image 1: phpMyAdmin database showing tables


So to follow on with this ‘little’ database story, this doesn’t happen magically. I wish it did. In another module we are learning how to use the framework Codeigniter with php and the aforementioned use of databases and tables to allow basic functionality to get front end project (allowing user to meditated with a chosen avatar and other users with their avatars) and get it to pass data back and forth to the backend; the database. 

My goal is to complete the steps of CRUD. Create, read, update and delete So far using a database from class called users I have accomplished some basic programming steps. The first thing that had to be done was to create a database, in this case users. It is located in a folder called NoticeCI that exists in a Codeigniter folder. This is a list of the screen shots of what I have working:
/User/getUser
/User/User
Link: ‘edit update details’;  User\getUpdateDetails
/User/saveUserDetails

Image of controller User not found
Image 2: User/getUser

Image of controller User get user
 Image 3: User/User

Image of user get update details
Image 4: User/getUpdateDetails

Image 5: saveUserDetails

Saving user details on the database
Image 6: saveUserDetails in database (row one) It says hi Fina in Image 7 and FirstName is Fina above 
 The last one on the list is giving me a lot of trouble as I cannot save the new user details to the database. I was able to do so on 14th March in class but not now. My databases should refresh to show the new details but it is not. I have looked though the notes and the function in the saveUserDetails but I am missing something I have checked the links also in the first file called userHomePage which was userhomepage. I have gone back to the User\User folder to find any errors below or the subsequent pages the path of the framework leads to but I cannot find the issue. On my localhost nothing is happening. No even an error!!!


Here is some of the code used for programming the above : 

public function saveUserDetails($UserID){
//prepare an array of user info submittd via the POST

  $user = array(
"UserName"=> $_POST["UserName"],
"Password"=> $_POST["Password"],
"FirstName"=> $_POST["FirstName"],
"SurName"=> $_POST["SurName"],
"Mobile"=> $_POST["Mobile"],
"AddressLine1"=> $_POST["AddressLine1"],
"AddressLine2"=> $_POST["AddressLine2"],
"AddressLine3"=> $_POST["AddressLine3"],
"Email"=> $_POST["Email"],
"UserID"=> $UserID,

);


//call the function in the model to do the update and get back a boolean flag
//$flag hold tru/false value depending on whether the update was successful or not
$flag = $this->User_Model->updateUser($user);

//pass $flag to function to determine whether success/failure page should be displayed
if($flag){
//set user details in $data - this will be need inthe userhomepage
$data['User'] = $user;
$this->load->view("User/userHomePage",$data);
}else{

    $data['msg'] = "error on update to user details";
    $this->load->view('mgspage', $data);
}//end function
}
}
Okay so straight after this at exactly 5.17pm on 9th April it worked! I decided to write about what was happening to see if it would help with a) frustration and b) identify any new patterns for me to see and then I then I just decided to go back on the getUpdateDetails page, refresh, input new data and presto. It updated the database. Wow. It feels great but like any decent creative multimedia programmer I will just be looking now to do the delete functionality as I am a full WEEK behind in class. 

What did I do? It was a small typing error – the file was called getUpdateDetails not getupdatedetails as it should have been. Oh my. Who said camel casing for programming was good? Moving forward I think it will be all lower case when I can when I am programming because let’s face it trying to practice creative multimedia programming is hard to begin and then trying to implement creative concepts and execute them over a variety of platforms is another!!!  

I went for a coffee today to take a break from programming php and it taught me two things:
1.       My FYP is useful – taking breaks & doing nothing are good for creativity! Promoting this value is viable in demanding situations.
2.       Whilst on that coffee break an hour ago I told my friend’s boyfriend about taking a WEEK to find an error and he said, I quote:  ‘Now you are programming’. So in a day to find two errors myself is a happy feeling.
The next step will be to create and implement the VanilllaCI around my project Curious Room but I have to go back first and fix the actual look and basic functionality of my project before I attempt to change them into php pages. In truth I feel a bit lost about the next stem and don’t know how to do it – I have just spoken briefly with someone in the learning center about how it ‘happens’.  Apparently it’s as simple as saving the dot html extensions as dot phps… ? Hmm.  
To finish now this is working:

User/saveUserDetails

and now I just need to get a message to the home page to say the details have been updated……

I don't know how at this point how much I will be doing with creative multimedia programming but I will try my best! 



No comments:

Post a comment