Making Parkwood Vale · Part 12 of 13
Part 11
Add books from the Google Books API through a new admin area, with covers saved to the site.
We give admins a way to add books. They search Google Books, check the details, and save the book and its cover to the library.
In this part:
0:01 The finished feature
4:46 An account dropdown that changes when you are signed in
9:50 Logout and an admin page only admins can reach
11:53 The admin search page
14:57 Calling the Google Books API
19:40 Reading the JSON results
28:58 Laying out the results
52:18 Passing a chosen book to addbook.php
57:38 The add book form, filled in from Google
1:17:14 Saving the book and downloading its cover
1:26:02 Fixing descriptions with apostrophes using real_escape_string
The star ratings are started here but not finished.
Software: Adobe Dreamweaver, UwAmp, HeidiSQL, PHP, MySQL, Google Books API, Bootstrap.
Transcript
- In today's session, we're going to be looking at Google Books API integration and
- how we can use Google Books to pull in information on the different books we want in
- our library. It's going to use the same form of search as we use with our search
- bar, Ajax form, which will then search through Google Books API and allow us to add
- the information to our database.
- We will create a small form that will allow us to change some of that information.
- So if we pull through the information about a book, we want to update a little part
- of it. We're going to include a form there so we can do that as well.
- Okay, let's get into it.
- Okay, so as you can see, I'm back on my student desktop and I've got Parkwood Vale's
- website open.
- From here then, I've already logged into my account and what I'm going to do is open
- up the admin section. On this admin section here, this is the part we're going to be
- looking at. When I was talking about APIs just now, I was talking about what happens
- here. So by the way, I've been Harry Potter.
- You'll see as it's searching through, it searches through all the different Harry
- Potter books. It shows us how many stars they have and how many people have rated
- that book. We also have in place who the author, oh, the name of the book, sorry,
- who the author is it's ISBN, it's publisher and a small description of what the book
- is about. All of this information here is pulled through using same sort of
- Ajax we used last time for our search up here for this search element here
- and it's not going to, well it is going to our public site, it is going to a page on
- our website but that then searches using a special search command Google APIs
- itself. So if I
- were looking two seconds ago at say the prisoner of Azkaban in this long
- mess here you'd probably find the prisoner of Azkaban there's the Chamber of Secrets
- the psychology of Harry Potter there are lots of different elements
- and they will pull through in different ways now this here what we're
- currently looking at is called a JSON object it's a JavaScript object notation a way
- of passing information from one server to another server, from front end to back
- end, to make sure that the information gets passed in a way that can be used by lots
- of different applications.
- If I take all of this JSON code and I go to a JSON parser website,
- this first one's just as easy as any, and I paste it there, what we will see
- is that our object has 10 items within it.
- Each item gets a kind, ID, e-tag, and link to it.
- Get rid of this advert for a second, and let's actually just jump down to full
- screen.
- With all of that information in there, we have the authors of the book, the
- publisher, when it was published, the description of it.
- So that there is the ultimate Harry Potter philosophy.
- We're not interested in that one.
- Here we've got Harry Potter and the Chamber of Secrets.
- Good starting point, and if I went back to Parkwood Vale, If I scroll up, Harry
- Potter and the Chamber of Secrets.
- J.K. Rowling, Bloomsbury, four stars, three.
- In here, J.K. Rowling, Bloomsbury, and if I look through, average rating three and a
- half, so I probably rounded that up to four, and the rating count is three.
- If I go back over to here a second then, we can see that picture is of what looks
- like a cartoon, an animated version of Harry Potter.
- you will see that we get image links.
- We've got a small and a thumbnail and if I hover over it it's exactly that same
- picture even down to the little page turn there.
- The reason for all of that is that it was exactly from this section that I found
- that information about Harry Potter.
- So that's what we're going to be looking at today.
- We're going to be looking at how we can use something like Google's API here to pull
- in that box information based around that search field that we have here.
- The first thing we need to do with our site is set up so that when we are logged in
- and we are on the my account page here we have that ability to get to an admin
- section if we are admins. So there's my admin section.
- So I'm going to go ahead I'm going to open up Dreamweaver
- and I'm going to make sure that UwAmp is running so let's check down here yes it is
- already running and there is my site.
- So let's close down these previous elements that we've got included and let's get
- started with this. I'm gonna start off by finding my header and in my
- menu system down here, then after my search bar, where I've got my account, this is
- where I need to make some sort of changes.
- So I want that now to change from just being a simple account button to being a
- dropdown menu. So if I go here and log out a second, I can show you there's the
- account button.
- And when I'm logged in, there's the account dropdown,
- to it.
- The way I'm going to do that is I'm going to put in place some checks here.
- This element is being shown, this ul section here is being shown to the user because
- they aren't logged in. So I want to put in a PHP tag.
- It's going to be an if statement and let me just put a curly bracket there and I'm
- going to close that a second and just go to the other side of my ul tag and make
- sure I close off that curly bracket.
- Now this if statement is our condition that we want to know whether or not our
- user's logged in. Thankfully we should have at the top here or we haven't yet but we
- should include our session underscore start
- so we can ensure that we've started our session in
- place. Now every time we load our page our session will be there and what we're
- going to down here is we're going to check to see if a session piece of data has
- been set. So I'm going to say if is set and that is going to be
- dollar sign underscore session
- and I want to know if session and we're just going to use email has been set.
- And I'm going to say that if that is set is equal to false so it hasn't been set
- show this menu option here our login screen let me save that push my
- header up and let's go to localhost
- now
- that's not showing anything so I'm gonna guess that if I went to forward slash
- account I am logged in it's come up here sessions already been started twice we can
- ignore that for a second don't worry about that error at the top there but I am
- already logged in so that's why it's giving me error that's why it's not showing
- that section I'm gonna say that if it is set else
- then what I wanted to do is display for me my
- drop-down menu so let's just chuck in a closed PHP tag here to make sure that
- we don't miss anything as we're going along so next up
- then what we're gonna do is use this else statement to put in an unordered list like
- we have here but this time around it's going to be more focused on setting up our
- drop down list for our nav items so i'm going to copy our unordered list here
- elements and just paste them below a second it is still part of our nav bar it still
- has its margins it still has everything in place we want it to it still has an li
- list item for nav item the main difference being that this one is going to be a drop
- down type so i'm going to put in drop down
- And our A class element here is going to be a class with a drop down
- toggle in place. So let's see if toggle's there.
- It is. And happy days. Now this is going to go to nowhere.
- So I'm going to use a hashtag there for my ahref, which I'm going to put that in
- place. It is going to be slightly different though, because it has a role.
- It's role is a button for us. as well as having our role of button
- we need to tell it that it's a data tag of bootstrap and it is a toggle element
- now this toggle is going to be called drop down itself and
- that's going to put that all in place so i've got my x elements set up
- the last part i need to do is give it an area
- and it is going to be expanded and our expanded here is going to be false meaning
- that it's not already drop down when we start now all of that's in place we
- just need to give it the unordered list elements that are going to go underneath
- where our drop down class is so our class in this element then is going to be called
- drop down because that is what everything is linking to it's looking for a toggle
- drop down it's a type of drop down it is working with our drop down it is going to
- be a class of drop down hyphen menu and underneath here then we will have our list
- items just like we standard have at the moment our list items are going to have
- their own classes so an a class that is going to be set as a drop down item
- and there's my item and let's just end that a tag a second there just so i
- can copy and paste these what we're going to have then is three of these.
- We're going to have one for my account to get to the account page.
- We're going to have one for admin, if they are admin, and we'll check that a little
- bit later on. And we're going to have one here then for logout.
- So if you are logged in, you can now log out by going to this page.
- Each of these are going to have a type of ahref to them.
- So, ahref equals, and they're going to go to the different pages.
- Now, I'm not going to lie to you, this is going to be the third time I've done this
- actual video. The second time I did it, it worked perfectly, but I recorded my wrong
- screen. so this is going to just go to account happy days i'm all okay with that i'm
- going to do forward slash account this is going to go to forward slash admin and
- this is going to go to forward slash log out now i have
- created these admin and account pages in my previous videos which were completely
- useless but never mind so let's bring these assets down i'm not interested in those
- let's expand these you can see here is my logout page what i'm going to do is i'm
- going to save this and wherever my header is gone it should now be alphabetical
- order and header there we go let's put that up so that's in place on
- my logout page then this is one that i did earlier bit of a blue peter moment let's
- check that in place let's talk you through what it's doing it is starting or it is
- destroying the session so there are no longer session details in place and it is
- just redirecting us straight back to the login page our admin account then our admin
- starts our session. It then checks to see if the session is empty and if it is it
- redirects us away from it. It includes our header information so we can do our
- connection and it does a test to see if we are the only person who is set as admin
- and if we are the only person who is set as admin then it is going to redirect us
- away back to the login page. Oh sorry let me try that one again.
- If we are admin is fine. If we're not admin so if the records don't equal one then
- it redirects
- brings us to this form page here.
- Let's create this form page. What I did was I copied the contents of my account
- page. It all looks very similar.
- And all I did was I removed the additional search that I don't need to do.
- I put in a form. That form there has come directly from my header section.
- It is the header section here.
- If I scroll down to it, if I can find where I've got it to, it is this form here my
- search and live search were then created corrected to be admin search and admin
- results and i removed all the elements the styling around this admin search that put
- it in that top corner and what i get is a screen that looks like this so i'm
- logged out here but it's giving me a bit of an error it's saying sessions already
- started it is a notice and i'm take you through how to fix that in a second.
- I'm going to log in and that's going to
- bring me to my drop down. I can go to my admin page which has the ability to search
- through my existing books
- but nothing else aside from that.
- If I come back here then you can see the H2 for my heading and my form to search for
- that. Now I said I'm going to show you how to get rid of this error at the top here.
- What this is saying that session has already started.
- It's been started on the headed page on line two.
- So it's going to ignore the session start.
- I'm going to go into UBank.
- I'm going to click on the little folder here, the same one we used when we went in
- to find the mail elements. But this time around, I'm going to be looking for error.
- And I'm going to search through and I'm going to look through until I get to the
- very end here and we get to the error handling
- And the error handling section we're looking for, let me just close that because I
- know I'm on the right section then.
- If I scroll down to it, states that display errors is on, display
- startup errors is on, log errors is on as we keep going through.
- And I think I passed it actually.
- There it is. It is this line here.
- Error reporting equals E all. If you have a look, it's actually line number
- 445.
- says is that it wants to show all errors warnings and notice in is notices including
- coding standards well we're not too worried about some of our notices so we're going
- to go for the second option here which is e all except which is what the tilde
- symbol means notices show all errors except for notices so I'm going to highlight
- that section there just copy and paste that into place and file
- and save and when i file and save that and close this you up is going to have to
- cycle so it's going to stop and start again
- let's just stop it all it's all completely stopped start it
- all again start it all back up and running all happy if i refresh this
- now
- we get the same page but no longer with that notice error at the top corner there
- so with that done what we're going to do next then is code the back end search
- because at the moment when we search for anything it's searching through our library
- book and we don't want that we want to search through google's library books i'm
- going to go back into dreamweaver then and i'm going to create a new file on the
- side here and call it online search.php.
- Now, unlike with a lot of our files, we don't need a connection to our database
- here. We also don't need to start our session here.
- This is a unique file in the fact that it doesn't really matter what comes before
- it. What I want to do is capture a response from Google.
- So I'm going to put in my response variable
- equal to and this is a bit of a strange one but it's a function called file get
- content
- get
- Contents and that will get the contents of anything that I give it as a URL
- And that's where I'm going to put in place and I'm going to use single quotes for
- this that google books link So HTTPS and it is www
- Let's make sure I got that right.
- APIs.com forward slash books, because that's the element we're looking at on their
- APIs. Forward slash version one forward slash volumes.
- Now, I've got those volumes there in place.
- I'm going to press the question mark and put in a queue for my get command query.
- And I'm going to say equals in title, which is what I'm searching for first of all.
- semicolon and then I'm going to tag onto that my get string so underscore get
- and in there I'm just going to simply put name because it's the name of the book
- that I'm interested in.
- I'm going to print out a second underscore r my response
- so you can all see how that looks
- when that comes back in and if I save that and I know the online search I was about
- half an hour ago when I first did this video through then we're going to stop there
- for a second while online search
- Now for you that's going to be about 2 seconds different James Bond is coming back
- and finished the video It doesn't like something different So, so far then we have
- created our drop down for our account Now the reason why it's failed on that request
- is that James Bond is actually two terms that my browser puts this dollar sign
- percentage 20 in place for. If I remove that and just put in James, I'm logging in
- page, I get my dropdown again in place.
- If I put in my search is there, that's fine.
- Admin search is here.
- That's fine as well. The name element should be to finish.
- I thought I had an element like that.
- Part two will continue in a moment.
- Encode function.
- Now that's giving me some sort of indication.
- something's not right because that should not look like that url encode
- and i want to url encode this section here
- okay so there's that there before we go too far
- let's copy that let's echo that and see what
- exactly it is doing just so that we are fully aware of what we're getting
- HTTP Google Books API.com James.
- Ah, did I do something wrong? Did I do HTTP?
- I forgot to put the S in place.
- It doesn't like unsecure connections, I don't blame it, but let's go here, let's put
- that up and refresh it.
- And there we go, we're getting all of that information back.
- And actually, with that in place, I can even go as far as putting in bond as a space
- URL in code element would take care of those spaces.
- If I just show you again with Harry Potter
- and search for that, it's brought back all this information about Harry Potter.
- We've got our title here. Let me just copy this and paste it.
- And this is what we're getting back.
- It's not coming back as pretty as that, but it's still the same information.
- If we have a look, The first title coming through is The Ultimate Harry Potter
- Philosophy, like we saw earlier.
- In our books, our volumes, if we go title, here's our first title, The Ultimate
- Harry Potter Philosophy. It's exactly the same premise.
- Let's go back into here then. We no longer need that echo.
- We found out my issue. My issue is the fact I forgot the S in my secure connection,
- and that's in place there. that file get contents is stored that contents in there
- but that contents isn't really that usable for us what's come back is our json
- string thankfully php has its own json functionality so json
- underscore decode and i want to get the response from
- what i've been given now if i decode that and let's fix decode
- there save that and push that up when i refresh it
- i now get a standard class object which i can actually for loop through
- so my response is there and i can do for and let's see each
- for each element in json decoded response let's give it those there
- as dollar sign kind to with.
- Now inside that section there I'm going to set up the details for each of these
- books so I'm going to say $deets as my details array equals
- JSON and I want to again encode this time so I can look
- through it in a different way and I want to JSON encode my response.
- My response is going to be set up with my books element.
- So I'm going to say there I want book is equal to an element and my book
- element is its own array and this will all hopefully make a bit of sense when I put
- it all into place for you in a second.
- So what I'm doing actually, let's talk you through it, it's a bit easier at this
- point, is I'm looping through each of these and outputting its kind.
- I'm creating a new array which is a JSON encoded array and that array contains a
- starting point of book so it's going to have lots of different books in place.
- Inside that book we are going to have an array of objects so let's bring this up to
- here there we go and inside the array of objects here we can put in different
- things. Now we're interested in title which is the name of our book.
- That is going to be our kind which comes from this section here and we're going to
- say that we want the volume
- information and the volume info I'm looking for is title now if I jump
- I can do a comma would be helpful but if I jump back over here a second so we're in
- kind and then we have our different items and inside our items section here
- we have our different kinds and we have all of our volume information is
- here so our volume information starts as its own class that has title in place
- subtitle and so on so I've got in place my title there I'm going to say
- my image that's the picture that we are going to use as our jacket image is going to
- be from our kind and then it is going to be the volume info again
- and this time around we're going to go to image
- links and we just want the thumbnail now not all books come with a different sized
- thumbnails so I'm just using the standard thumbnail facility there I don't need that
- at the moment I can just tap that in so you can see it clearer
- I'm gonna say that it's author or authors given the fact that there could
- is set to the dollar sign kind again.
- We're going to do the volume information again.
- And this time around, it's going to be authors.
- Now, that could come back blank.
- That could come back that there are no authors whatsoever.
- So what we're going to do is check to see if that is equal to zero, or if it's
- empty. And if I open up a bracket here, and I say that authors
- doesn't equal null, I can use what's known as a tinary if, so
- an if function in one line, to copy that information and put that there.
- The else within our tinary if comes in the form of this semicolon.
- So what this tinary if is saying is if that
- authors section doesn't equal null, then set the information to what's in the author
- section, otherwise set it to zero.
- So I can work with it later and I can understand that it's a zero, so therefore
- there's no information there. And I could probably put that in for a lot of our
- information, because not every single book is going to have authors on Google's
- site. Now, every book's going to have ISBN, publishers, categories, all the other
- bits and pieces aren't always going to be filled in from Google.
- So I'm going to copy that and paste that there.
- After authors, what I'm going to do then is put in my ISBN.
- I want the ISBN number, which is coming through from the volume information again.
- And this time it is going to be in the industry.
- And it is the industry identifier.
- and that's that set in place and again if it's null then give us null otherwise give
- us the industry identifiers I'm going to go on to the next line again then and I'm
- going to put in place the publisher and what I'm doing is taking from the
- complicated google side of things through to my basic easily understandable for me
- side of things and this time around our volume information we're looking for is
- publisher and I'm going to do the same thing here so publisher
- and that's going to say zero if there's nothing to be seen and let's put the next
- one in place for category and again
- just volume information for category making sure that's all in place the only
- difference being that it could have multiple categories so in google that is coming
- through categories. Now you're probably at this point looking at this going how do I
- remember all of that? How do I know what's going on?
- That's because in this section here, let me just get back to the right window, all
- I'm using is these information points here.
- So in this section here my volume info is there.
- I've got title, subtitle if I wanted it, authors.
- If authors was empty that's it'd be a zero.
- I've got publisher, I've got industry identifiers, and it's coming through and
- pulling through my industry identifiers.
- It's got categories. All of this information is being pulled through, and I'm just
- looping and putting the different information in place.
- Now, I'm going to do the same thing again with description, so copy that, put that
- there, change it to description.
- And this is going to build up an array for me of all the different books that google
- are giving me so let's see description and
- we've only got two more so i might as well go through all of them number of rating
- and average rating so in there then i'm going to say volume information
- rating count rating
- count and again
- ratings count that's I'll leave that ratings count that's how many
- people have given it that star rating and then the last one here is going to be
- average rating so instead of ratings counts there there and there I'm gonna say
- average rating
- Have I spelled rating right there?
- Who knows? We'll find out. Now, that should populate my database.
- Oh, sorry, not my database, my array with my information that I want.
- So let's just see. And I don't want that there.
- I want that there.
- So this square bracket here, this square bracket ties in with this square bracket
- here for an internal array.
- is called book and then we got our JSON array there.
- That's going to loop through each of those and all I'm going to do is come down here
- and simply say print and what do I want to print?
- I want to print my deets and actually I want to print our deets.
- save that i do need this back now to be able to push that up and
- let's refresh this
- and that hasn't quite gone as i expected so let's have a look at why
- that's why because even though it comes through and it's a kind we are looking for
- the items within that kind element there.
- I didn't put the items in place.
- So what we need to do is say that when we've decoded it,
- start inside items.
- And if I save that now, and I put that up,
- what we'll get when I refresh it
- are all of our Harry Potter book informations for our 10 books within that section
- there. Doesn't look very pretty, doesn't look like much at the moment, but we're
- going to go and stylise that next.
- going to do that is we're going to loop through this details array.
- What we're going to do though is come out of PHP.
- So the next couple of bits and pieces are going to be pure HTML just to give it its
- style of how we want it to look.
- So I'm going to say div class equals and again this is going to be
- following the same MDs styling that we've done previously.
- So I forgot about PHP. There we go.
- Div class MD12 and let's end that div there.
- Now inside there I'm going to put in a row.
- Div class equals and this is going to be row with a
- margin to the top of two.
- And then I'm going to put in place some information based around our box.
- realistically i want this to be going on while it's looping through each of these
- elements and they're just hidden in the background there so i don't want to end my
- php there i do actually want my php there so i don't want that end of that loop tag
- there i'm going to come out of there entirely i'm going to come down below here then
- put in place another php tag just so that it ends that loop tag there
- and that should give me all of that so what it's going to do for each
- one of these is it's going to create a column of 12 with a row inside of it and give
- me some information inside of there the very first thing I'm going to do is put in
- place my div class and it's going to be a row for my book image my jacket
- and it's going to be not row sorry it's going to be column of md3
- inside there we're going to be using an old-fashioned image tag
- with the source because we can't use webp images until we've
- actually captured them i want to in there php
- echo out and i actually want to echo out my image information
- my kind thumbnail that we've got from
- and echo out that kind thumbnail and close that image tag.
- Now that will put in place my image and set it to however it is.
- What I do want to also do just very quickly, let me check.
- I haven't finished my PHP tag off there.
- Close that off. Brilliant. I'm still inside there.
- I'm going to say width equals 100% on my picture, just so that my
- picture is taking up all of its parent space that
- Now the next section there is going to be a div tag again, is going to be that
- class,
- col, md, and this time around it's going to be a 9.
- And I'm going to put that in place and terminate that.
- And I'm going to start structuring the information based around my book about what I
- want to have in place. So a heading number 4 is going to be put in place for the
- title of my book. and again I'm just going to use PHP tags to echo
- out. Now I should be able to echo to make things a little bit easier
- for me possibly my details but I'm not going to.
- I'm going to stick with what this is and echo that title and
- then end that tag and that's there.
- Just for a second let me save that and let's put
- refresh and see how it looks different now, if at all.
- That picture is huge, but it has the text there.
- Another huge image with the text next to it.
- So let's remove this width a second just to see how that impacts
- upon its usability.
- Okay, so we're starting to get a bit better structure there.
- Now, I'm going to put in some other bits and pieces.
- I don't necessarily need all of the information in place, but just some of that
- information. What I'm going to do next then is put in a p tag and I'm going to
- simply inside my p tag there, echo out some of the information that I want to
- display that would be handy to know at that time.
- So let's do a PHP tag and echo this kind volume information
- and I do want to echo out my author
- and I can end that
- PHP tag there I'm going to put in a break tag so a simple
- br tag and then I'm going to do a similar sort of element copy this paste this here
- but instead of author what I'm actually going to is put in place,
- well, I'm gonna put in place the ISBN.
- So let's go up to here, have a look.
- I got my industry identifiers, let's copy that,
- and paste that here.
- Now if I save that and put that, let's see how that looks.
- Ooh, it's not happy with something on line 31.
- line 31 echo there we go and that's because I copied the
- whole of my TNRF I don't need the whole of the TNRF I just need to have that
- fresh Harry Potter array array right okay so we're saying array array on these
- elements here that means that we have been given an array but we're trying to print
- it as a string and it doesn't like that but if I just simply said at
- Programmatically, that means the very first position, it will print the first of my
- records. So now, I get Harry Potter, I get J.K.
- Rowling's. It's not happy with something converting from a string on line 31.
- Okay. So what this is saying to me, then, is that even though it was an
- array, it hasn't found anything.
- so if I was to remove that assignment and I
- was to refresh this now I get Harry Potter an array or JK Rowling sorry an
- array but it's telling me that if I print underscore
- r because I wasn't happy two seconds ago with how I echoed that out
- let's see how it does it if I printR it.
- And even though it's an array, it's given me other options.
- So inside of the array, we have its type with ISBN and its identifier.
- So if I was to go to array position zero and
- put that, we're now given, are we looking for the type ISBN
- or its identifier? Or realistically,
- identifier. So if I did identifier there instead and I change that back to
- an echo, we now get
- that correct information. And as we go through, it's there for all the different
- books, depending on the different titles.
- It still tells us the ISBN numbers for all those different elements, all those
- different books.
- As well as the ISBN information then, it would be handy to know who the publisher is
- and we're going to do the same thing as we've done here so we're going to have a
- break here a br and then we're just going to copy this section here and drop the
- publisher in instead of the author now i don't think publishers
- are ever done on a array so we can just do that as a single publisher element and
- let's drop that up
- and we've got the publisher as well and the very last thing that i was going to set
- out is a small description of the book and I don't want to do the whole
- description. So when I do the PHP tag here and I do my echo
- for my description,
- what I'm going to do is actually use a substring, a
- substr of my
- kind, volume, and this time I want the description.
- and the substring I want, so let's see, there's that substring there,
- should be from position 0 to position 100.
- And what that means is, take the first 100 characters of my description.
- And yes, it's characters, not words, so it would sit in the middle of a different
- section. So on line 33, undefined function substring.
- What have I gone wrong there? I've done string wrong.
- I always tell students off for doing source wrong.
- I've done string wrong. It's sub str for string, not srt.
- And if I refresh that now, we get the first 100 characters.
- So just to make that a little bit nicer looking, what I will do is do dart and
- speech marks 1, 2, 3. Just so you can see those ellipses show you that there's
- something else in place after it.
- now with all of that in place if i refresh this we get our little elements there and
- i can include if i go back to my
- search element i should have in here
- my star rating let's copy this code
- onto my online search and paste it below.
- Now this is PHP code so I will have to put it inside a PHP tag again.
- Star rating should be five. Star rating this time around is going to be from our
- ratings section.
- Let's see I have volume average rating.
- Let's copy that.
- and in my rating section here then I'm going to paste my average rating
- and that rest of this function should work in exactly the same ways it
- does on my other page so what that's going to do is put those spans in place which
- when we first see them we're not going to see the spans those spans are going to be
- invisible because they are not linked correctly.
- They don't have their referenced elements.
- But when we put it into our actual admin page in this section here, then
- we should be able to see it.
- So I've gone through, I've set up that online search.
- Now all I've got to do is send through information to change what is inside my name
- element.
- On my admin page then, and actually it was on my footer element
- within the admin search so live search on search there
- admin results we don't want to do live search for search we want to do
- live search for online search
- this time around and q equals this true okay
- it's not going to be query it is going to be name
- equals that. If I put that up on my footer, that should allow me to do
- my admin search.
- That's searching my database.
- That's still searching my database.
- Let's see what's going on here and zoom out again.
- I will zoom back in so I can go through it, but it's just so much
- my search I swapped the wrong one so let's go copy
- paste cut paste save
- and put that up so making sure you're on your admin search and you're making it
- change into the online search rather than your normal search I've just put that up
- then let's refresh this page a couple of times harry
- potter and the Deathly
- Hallows.
- And that's searched through and it's found me lots of different versions of Harry
- Potter and the Deathly Hallows.
- It's got me all of these different versions of it based around the publisher
- details.
- We've got Bloomsbury Publishing in place there, Bloomsbury Children's Book there.
- We haven't quite spaced out nicely.
- Let's go back to our online search here scroll down and
- let's put a break line in there so that should go to the next line now this
- didn't seem to be doing anything for me at all I wonder why we'll have a look at
- that in a second let's first of all put not enough but a online search back up and
- re I don't know why refresh is an ajax search it shouldn't need it Harry Potter
- there we go and we're starting to get some black stars in place.
- Harry
- Potter
- and the Deathly Hallows is coming back there.
- It's given me three black stars for some reason.
- I'm not getting any gold stars, but it is.
- Now I'll give you my description on my second line.
- Realistically, I didn't need to do that.
- I could have that set to a much higher number if I wanted to and put that up.
- And just to
- that changes it's now giving me 500 lines of it rather than just 100 lines of
- it or 500 characters not lines sorry but let's tackle this gold dot element then
- so um let's see star is five star rating is kind
- volume average rating i wanted to round this up have a look at a second
- four star rating is zero to, well star rating is less than, there we go, and
- it's got checked there.
- Did we do something special with checked on,
- where did we put the CSS for checked?
- Okay, checked is on our header, so it should be in place, goldenrod.
- Let's go into inspect,
- and they are stars they are not checked stars if I set it to
- check it does go gold so it's not the CSS that's a problem it is the initial PHP so
- online search star rating what do we get
- let's have a look. Let's echo star
- rating and see what we're actually getting.
- Nothing by the looks of it. There are no numbers coming back whatsoever.
- Inside there, inside there, inside there.
- We have our stars. I don't know why we never have three of them that's a bit strange
- it should do five of them but our average star rating
- isn't given us anything um let's go
- star and put that up um online
- search
- okay star is still giving us nothing after it fair enough
- in there then
- volume info average rating let's have a look here we want
- items and then we're in volume info here and
- average rating should be there.
- Okay.
- Let's just have a quick look at these books a second.
- I'm going to go print underscore r dollar sign
- kind volume info.
- Okay,
- save that, put that up. So that's gone to there.
- And now if I refresh this, oh, shouldn't have done that.
- Harry Potter and the Deathly Hallows.
- That's giving me all of this information about Harry Potter and the Deathly Hallows.
- I've got the title, publisher, published date, identifiers
- my ISBN number that's fine no it's not content we've
- got our thumbnails from our images there it is and small thumbnail
- why is that not
- okay so average vision should come before image links reading modes text
- print book, not much sure.
- Let's get rid of that.
- content version
- Pause this a second.
- And volume info should have industry identifiers,
- reading modes, categories and average rating.
- Average rating does exist there.
- But they're still coming back with nothing in place there.
- So, star rating equals kind volume info average rating.
- For each of the average ratings
- is less than the star rating
- that's baffling me i honestly don't know um why is it coming up and it's not got
- volume info star rating even when there's star ratings included if i was just to
- spin this around a second and make it so that they're all three star books let's
- just double check the star rating element is working and Deathly Hallows yes they're
- all three star books and in fact actually they've gone up to a four star they should
- have five there equals five that's going in once beforehand so perhaps
- star rating
- minus one
- No, that's coming out fine, so star rating should definitely be just SR.
- plus one, not plus 10, plus one would be
- enough.
- That should then at least bring us to our...
- Nope, it doesn't want to do five star, whatever I do.
- Strange.
- Dollar sign s r.
- Dollar sign s r should have come from there.
- No, I'm gonna remove it from there.
- Tackle it later. So we've got that there.
- Now, all of that is in place. All of that is set up so that when I do search for a
- book, and now I won't have any issues.
- I didn't put it, did I?
- Let's try putting it correctly.
- And now when I search for a book, it's gone there.
- That's all perfectly fine. What we need to do is we need to have an element now that
- when we click on to add a book, it passes this information to our ad book page.
- We haven't created our ad book page yet, but we will do.
- And the way we're going to do that is we're going to utilize this deets array that
- we set up earlier.
- It wasn't just for the sake of it.
- It wasn't just doing it to get you to type out a lot of code.
- What I'm actually going to do is, outside of my p tag,
- create a button, which is an
- ahref, which will take me to my ad book page.
- And I'm going to add some styling to it.
- is going to be type of BTN and it is a BTN primary
- and it's just going to simply say add book.
- Now when I put that in place and I refresh this
- and I search for Harry Potter and the
- deathly hallows, you'll see that we have this add book page.
- When I click add book, it takes me to nowhere because we haven't created it yet, but
- that is in place. We want to utilise and hijack, I suppose the term could be,
- the get command, and I'm going to say book equals,
- and inside here then, I'm going to put a PHP tag to pass that information across.
- And the PHP tag information is going to be my array.
- I can't simply print that array, but what I can do is encode it in a specific way.
- You'd have seen some sort of encoding using base64 whenever you've used
- the web and not realize what it is.
- Effectively this is going to be a very long string that doesn't look like much
- but the computers understand that it's encoded in some way.
- And what I'm going to be passing through my Base64 encoded section is simply
- my DEETS array so far.
- And as that goes through then, that should set up, and if I push that up, I'll show
- you what I mean. On here, Harry Potter and Deathly Hallows, and if I hover over it,
- it's not actually saying anything because I forgot the word echo.
- And let's push that up again.
- Deathly Hallows. Hover over it.
- And down in the bottom corner, in that long string, you can see that extremely long
- string there that has book equals, starts with
- EYJB29RLJP. That information can be
- reverse engineered to get it back to how we want it to look.
- So if I go in and add in a add book page, new file, call it
- addbook.php and
- open that up.
- And all I'm going to do to start with my addbook is simply php and print
- underscore r.
- And I want to print underscore r the get information.
- That is book.
- and we'll see how that looks. Let's end that PHP tag.
- Add book gets posted up. Now if I click onto here, we get this very long
- string.
- What I'm going to do is copy that string and very quickly jump into
- a base64 decoder.
- And if I paste that long string and decode it, you will see that
- it contains the information that we have set up.
- Okay, our average rating is zero.
- We had that issue two seconds ago.
- I'll deal with that later. I'll need to have a look at why that's coming through as
- zeros. But you can see the book title and all the other information that we have
- laid
- If I went back onto my site, and I go back to the previous page, and I put
- in Deathly Hallows, and I use a different, so the Gryffindor edition there, just
- to show that it's not just a coincidence, let's copy that, and paste it, and I
- decode it, it is now the Gryffindor edition, it is much smaller in detail.
- That's because I've passed that information through in a way that my computer can
- understand. I can go in and base64 underscore decode this.
- That will allow me to put it back in as standard edition
- PHP code.
- And now, when I reload this, it doesn't like something on that line.
- Why did it get rid of that? Dollar sign underscore get.
- There we go. it wanted it to be something in base 64 and it should have been and
- there it is and it's come back here as my json code if i want to get it further
- i want it to be json underscore decoded
- that's what happened okay base 64 thank you very much uh
- decode dreamweaver for making things more difficult than it needs to be and we
- have that in place. Let's put that up, refresh that and we know how our standard
- class object and we can use this information to effectively create
- a insert that allows us to insert this book's details
- into our library but also in a way where we can edit some of that
- information.
- What I'm going to do is have a quick pause, have a quick drink and then go now that
- form to add it to our database before submitting that book in place.
- Okay, so now we're at a stage where if I was to click onto a book and reload that
- book
- on that page there, let's put that page back up,
- it will give me all of those books details.
- I've declassified the books, I've decoded the book's details, I've Base64 decoded
- that long string, I've JSON decoded it back into its array format, and I'm printing
- it. That's not really that helpful for anybody, but we've got it there to look at at
- the moment while we structure the rest of it.
- The rest of our page then should look for something similar to our admin page.
- So I'm just going to hijack that, copy that, add book, and paste it all there.
- We do want our PHP session starting we do want to check if this session
- hasn't been set if so we're going to kick them back to that login page they should
- always be your first port of call so let's check those at the very top there then
- and i do want to include my set uh my connection details and my header details so
- i get my same layout now this section here where we're going through and we're
- querying our database don't really need it just yet we will but not right now and
- we've got our main our backgrounds and different elements in place.
- Perfect. Inside our container then, our rounded white box.
- We have our details here, our row for our ad book, and we're gonna be placing in the
- elements to show our book. Ad book to library is still a valid name, and we
- have this section here there.
- Let's just tidy up some of this indentation, especially with it being so large
- formatted. It makes it a bit easier to see exactly
- right there, there and there. Let's save that.
- And actually this print here, I'm going to take that print out of there and just
- inside here,
- PHP, and I want to print that element, save it,
- and let's put that up. When I refresh this now, it should look a lot more like we'd
- expect it to. It's got our basic elements to it.
- It's got the starting points. It's got the logout pages and everything we needed to
- have in place. Perfect. We now need to stylize how our form is going to look.
- We'll come back to where our form is going, what's happening with our form in a
- minute or two, but right now we're going to stylize some elements within it.
- First of all, I want a lot of hidden input elements.
- and input I'm going to put in type hidden
- equals hidden and some of these details are in place.
- Now actually let's think about this in a different way perhaps I don't want the
- inputs to be hidden just yet let's get that up from there so I can see this code a
- bit clearer and I'm going to put some different elements.
- So let's go for heading number two, shall we say, and let's say title.
- And underneath that, I want an input, which is going to be
- type equals
- text and its value is going to
- be equal to let's just decode this and store
- this in deets again deets equals that inside here and
- then what I'm going to say is php I want from
- deets
- a book and I want its title
- and let's close that off
- now I've done all that let's just push add book up again
- and see what happens empty inspect
- value is empty because I didn't echo.
- I still haven't echoed.
- Echo an ad book.
- Okay.
- Deets book title.
- Let's go print underscore r
- dollar sign deets.
- We're getting somewhere. We've got some information in place.
- Standard class book. It's got all of these information bits and pieces in place.
- What if I said Deets book?
- And title's only got... Right, okay.
- Let's go back. Deathly Hallows,
- a book.
- Online search. That definitely says title.
- Let's just check that up again, though.
- Online search.
- Title! We're getting somewhere.
- Let's go back to Add Book and let's put in title
- with an arrow.
- book except for the wrong page up and there we go okay
- so we're getting somewhere entirely let's drop that instead of print r to simply
- echo it and there's our deets are in place there they do need to be tabbed
- in let's check that back over there that's the
- value and let's go class equals form
- control. There we go. Title is now Harry Potter and Deathly Hallows.
- And let's capitalize that. So we can do the same element then with all of the
- different parts within our book.
- We can set all of the different titles to different sections that they need to be
- set to.
- I'm going to have to zoom out on this section here.
- I am sorry for that, but I cannot see it that clearly from there.
- So title is in place. I'm then going to go through and put it in as a paragraph tag.
- The next one up then I'm going to have is ISBN.
- And after ISBN, I'm going to do the same thing I've done here, but swap it.
- So instead of saying title, I say ISBN.
- Save it. And let's put that up.
- when I refresh it ISBN has come back as an array as we've seen previously we want
- the first position and we want the identifier
- let's put that up
- and refresh it and we get our ISBN number and we're going to do the same thing going
- all the way down now I got that as a title I could but it is label
- and end the label
- and have that there, put that,
- and it just gets rid of some of that spacing to make it a little bit neater.
- I'm going to do the same process all the way down, putting the different elements in
- for the different parts of the book.
- So label for author,
- and that's going to be identifier, author, and the
- first element.
- And let's put that. working our way through our different
- elements that we have passed it in deets which was set up here author
- is pluralized authors i want that to be authors and save
- that put that and refresh it and it's got our authors in place and we're just going
- to go through each different field making sure they're all in place one thing i have
- forgotten as i'm going down i do need to put
- This one here is going to be title.
- But the names should match what is set in my HeidiSQL.
- So HeidiSQL, let's have a look and open this up.
- In my books section, in my books table, I've got name, author, publisher,
- ISBN. So name here is going to be equal to name my
- book.
- name here is going to be equal to ISBN my ISBN
- name is equal to and let's double check
- our I've done it capital A for author just to make sure I got
- that in place as well and they're all going through each one at a time making sure
- that they are in place to match these sections here
- So next up then, let's copy these elements down.
- Let's go publisher, publisher,
- and again, just a single publisher,
- and it was probably lower cased.
- Just as I'm working my way through,
- refreshing the page just to check it's there.
- Bloomsbury, perfect. Next one up is description.
- description, nice and simple. That's what we call description and
- have its description as its content.
- There it is. It's got the full element there.
- I could set that to text area, but there's no real reason for it.
- And I'm going to come on to the next one as well.
- I'm going to say
- average rating, and that is going to be kept as rating, and it should
- be average rating.
- And I've got the rating element there, available copies, and jacket image are the
- only other two. If I check that up a second and refresh this, then average ratings
- come through a zero.
- Now, with available copies, that is going to be how many books we have or how many
- editions of that book we have.
- I'm going to say over here very quickly,
- available
- copies.
- And just make sure I'm matching that spelling in my name.
- copies.
- That isn't going to take a value because that isn't going to be coming from our
- element there. We can set our text to number.
- And when I put that up here, what that will do for me is when I go
- over to here, if I try and put words, it doesn't accept them.
- When I put in numbers, it does.
- I can do the same thing with average rating.
- And let me just go back over here a
- to number, and that's almost perfectly in place.
- We will put in place a hidden item, and our hidden item, I'm going to go to the top
- and put my hidden items all at the top for anything I want to hide, but it's only
- really the one. Input type is going to be hidden, and that is going to be
- for our jacket image, and what did I call it over here?
- I did call it jacket image,
- and say name equals jacket image and say value
- equals and just to try and keep it some sort of unified i'm going to keep it as the
- isbn for the book
- and
- have that there now if i was to save that and refresh this
- here. If I inspect it in my body, in my
- main container, or even my main up here, nope, it is
- this main here. Too many mains.
- If I expand this out a few times to get to my form,
- you'll see there's an input type and it's a text and
- And it's not actually showing my input type hidden, which is ironic.
- Did I put that up?
- There we go. Input type is hidden, and it contains my name and my values and my
- other bits and pieces. So they are all there correctly.
- If I was to submit this, I'd have no issues.
- It would submit to my database.
- It's not really giving me my image in place.
- So let's correct that then. I have here my row for my ad book.
- div class equals col md3
- again and that's where my image is going to be I'm going to do div
- class equals col md9
- and that is going to be setting up
- my form so So I want to tab that in and then everything
- inside my form all the way down to here, all of these elements need to be tabbed in
- as well.
- And I can end that div there and that can come back one.
- And what I'm going to do is you're going to separate it.
- So on one side I have my picture, on the other side I've got that image, all that
- text. And if I put that up right now and refresh it, we'll get the same thing.
- Oh, it worked this time, last time.
- If you remember, it filled the whole lot of screen.
- I had to put an image there first.
- In here then, what we are going to do is put in our image, its source, because
- again, it is not going to be in WebP, so there's no way we can use anything other
- than its source. And we are going to echo from our elements, from our deets, which
- actually are done before this.
- So I need to move my deets up here, and that should put that in place.
- Echo, there we go. I want dollar sign, deets as a book.
- and within the book if I open up my online search what did I call it I just called
- image nice and easy I want its image now if I save that and put that up
- and I refresh this everything breaks pretty standard really let's put that
- there and now nothing should have broken at least it just wouldn't show me my
- picture that's fine I can live with that I can solve that one as we go through
- it's book image deep book image should be there that's fine there let's bring that
- right back perfect we can get rid of that start time get rid of the end tag and they
- just save there
- amazing there right image online search
- deep book image image thumbnail there okay that should be fine because it did work
- on the other page as well um let's just go by here a second where
- i can see php ah already seen my issue before i
- even had chance i'd forgotten to php i just done the question mark
- he says with quite a lot of confidence because that worked for perfectly fine now
- when we've done it and set out in this way what it means is that if any of these
- bits of information need to be changed in any way they can be changed
- so for example this average rating there was zero I could put that back in as 4.5 I
- can say that there are 10 copies of this book that are available and there is the
- poster picture for it what I'm going to do
- is submit all of this information back to itself.
- I know that sounds strange, but in my form details, wherever the start of my form
- was, I do need to possibly move some things around with that.
- We'll leave it there for now. We'll possibly do it in a different way.
- I'm going to say that the action for this form
- is going to be set to itself. Add book.
- post method equals post.
- So when I submit this form, what it's going to do is try and send the information
- back to itself, where it got it from, and process it there.
- And all I've got to do is put in a check, a catch, to see if it
- has anything in its submit.
- So I'm going to say input type equals
- submit.
- I'm going to say that its Its value equals
- addBook.
- Its class is a BTN, BTN primary.
- And that's that.
- Let's put that up and refresh that.
- AddBook is our button there. I've got a bit of a margin on top of it, so I'm going
- to say margin top is equal to 2.
- Put that up,
- refresh, and we get that there.
- If I hit this button now, it's going to redirect back to the page I'm currently on,
- and it will get rid of all of this get string.
- And now I've got no information there.
- Exactly like I expected it to do.
- I hit that and it disappears because it's no longer in the get string and that's
- what I want
- what I'm going to do is go up to the starting section on my page
- and up here before I go into my deets or anything like that I'm going to check
- to see if dollar sign underscore post
- has set ISBN because I'm not going to be accepting any books that haven't got ISBN
- set in place. If it has got ISBN set, then we're going to do something
- different. What we're going to do is we're going to put in place an insert
- statement, so $SQL
- and I'm going to say actually rather than insert replace
- into books and I'm going to
- say what it is I'm giving it to replace into books so that would be
- name ISBN
- and all of these categories
- description,
- rating,
- and jacket, image, and available
- copies. So I'm giving it all of that
- information
- to use within its insert statement.
- Its values are going to be from our post.
- So 1, let's just do 2, 3, 4, 5, 6, 7,
- and 8. So that's 1, 2, 3, 4, 5, 6, 7, and 8.
- And each of these is going to be from $sign underscore post
- and then their relative names, which is where naming them, the correct names across
- the top there, becomes much simpler to manage and maintain.
- So if I just do this a second, it does make it a little bit easier.
- So that is then going to be ISBN.
- And then inside this one, it is going to be author.
- Inside this one, it is going to be publisher.
- Inside this next one, it is going to be description.
- Inside this one is going to be rating.
- Inside jacket image, we are going to use ISBN again.
- And that will all make sense in a second.
- And inside available copies will be the available copies.
- So that's going to post those elements and put them into our database.
- Our jacket image does need to be copied into place, but we're going to do that
- separately. And then we've got all of that information there.
- Now, to get our jacket image and to pull that in from its
- location, the first thing we need to consider is where it actually is.
- If I go echo $sql for a second,
- when I post to it now, I
- didn't put it. I'm forever not doing that.
- There we go.
- Here it is.
- We get this string here. So, replacing the books, let me just put that in as a new,
- nothing for a second. Sorry, I don't understand.
- Shut up, Siri.
- No, we're off. So, let me post.
- Thank you. So, as I'm saying, replacing the books, name ISBN there, the values are
- coming across here.
- And as I go through, we have our jacket image, which is coming here.
- So, we don't actually yet know where our picture is.
- No. So what we need to do is on our ad book, where we did our hidden
- for our jacket image, and I said the book there, I was thinking along the right
- lines, but I was slightly ahead of myself, and I hadn't quite realised that actually
- we do still need to have our image set to us.
- So if I save that, and I come back up to here, and this time,
- all I want to do is post our image.
- So I can save that. It was only image, not images.
- It was jacket image, to be precise.
- Save that, and put that.
- Now, let's go back a page, and there we go.
- That's what I expected.
- one long URL which will take me directly to that picture.
- And what I can do is I can use that file get content to find that
- picture like we did previously.
- I can say that the content for our picture
- is equal to file get
- file underscore get and I want underscore contents
- and I want to get those contents from my post image
- now once I've got that
- I want to write it to a place within my folder structure so I'm going to
- image equals, I want to fopen, which is going to be an
- open command to create something.
- I need to tell it where to store it, which in this occasion is going to be in my
- image folder. So I'm going to say full stop forward slash, in speech marks,
- full stop forward slash image,
- forward slash jacket.
- And that's where I want to contain it.
- And I actually want to give it inside that jacket, the ISBN name.
- So I'm gonna say dot, dollar sign, underscore post.
- And I want ISBN as its name.
- And use that dot to concatenate again.
- And I want to store this as dot jpg.
- So it's storing it in that location.
- opening that comma to write information to.
- Then what it's going to do is fwrite,
- because I've f opened, I'm going to fwrite.
- And what I want to fwrite is to my dollar sign image, my
- opened image, my dollar sign content.
- And then once I'm done with that, I'm going to do F close and I have to tell
- it what it is I'm closing so what I should do is produce my
- SQL statement get the contents from that picture I've sent it and in my
- images folder with the ISBN as the name save it as a jpeg in that place
- so if I save that I put that so it should work without me having to...
- Let's go back. I shouldn't have to write to the database, but I should be able to go
- there. It's come back here. It's got rid of that information.
- And if I go onto UwAmp,
- and UwAmp www.imagejacket,
- written today, the 9th of September at 5.30,
- picture so it's copied it directly from the internet into my documents as that jpeg
- file for me all I have to do then is execute this SQL command
- to make sure that it puts that book into my database correctly so I'm going to do
- dollar sign connection I want to query
- and the query it's going to do is dollar sign SQL
- and put that in place.
- And if all of that has happened, I need to go back to my, I need to
- header location and I want to change that to admin.
- Now, let's put that up.
- Let's go back a page. There it all is.
- Available copies. I'm going to say three.
- Average rating. I'm going to say three.
- I'm going to go add book. It's brought me back to the library.
- So it's
- we know the picture is in place if I refresh this do we have that additional book
- no one of these days I'm gonna do something right first time okay
- let's have a look and see why we don't let's go echo dollar sign
- SQL and then die
- bit severe but it's not behaving so let's kill it and let's go back
- I'd work
- there's my add command there's my replace let's go copy into my
- paste and
- all looks pretty good to me let's go hit that and see what it says you have an error
- near there the horcrux himself to be okay
- okay let's go reform my sql and you're also going to help as much as i wanted it to
- the issue is in this section here.
- Voldemort's.
- Gotta love it when they use correct English.
- Okay, we can overcome this though.
- That's not the end of the world.
- What we need to do is we need to set our description
- to be in some way edited. So if I put it as a
- json, no, json underscore encode and I
- just simply json encode my description that should work I
- am going to think ahead for once if I have an Irish author oh hey
- oh can I have anything like that or a publishing body that has a
- pluralized name that's going to give me the same error so let me put that up there
- let's go onto here and back
- paste and let's copy this this time
- and go paste
- what we should get instead old and what's it still there
- nothing actually changed.
- That's annoying. It could have been me.
- JSON encode.
- Okay, add put.
- No, that didn't change. Okay, well, we'll do it the other way.
- Rather than JSON encoding it, because JSON encoding clearly isn't actually being as
- effective as I was hoping, we'll base
- 64 end code.
- And now, if I put addbook up, this will look really strange.
- Addbook, and they are base64 strings.
- As I hope this time around. Copy, and let's go paste,
- and that's all in there.
- hmm no I'm not happy with that solution to be honest with you that's not the
- cleanest way of dealing with that option real escape string
- that will work I can put that in place rating field is
- not happy with I probably called it something wrong r8
- ratting there
- that's not going to give us our answer though that's not going to put it in place
- I've done rating the save that now that will go through and that will insert
- correctly and that would give us that extra buck I'm just not overly keen
- there but that being said I can get rid of that element there I can get rid of that
- element there bring that back save that and upload that and that would allow me to
- add a book that would go into my library and I can come back then straight to my
- admin page.
- Add book and go back to my
- admin page. Find another book um
- Lord of the Rings
- Fellowship of the Rings to Towers add book, it brings it through add book
- and in my database
- it's not giving me the additional Lord of the Rings book but I bet you in Yuan
- no that's Heidi, Yuan I get an additional jacket image
- okay Why is it not liking that?
- Echo, $SQL.
- fairly certain I don't usually do a die in that sort of way but I'm pretty sure it
- works
- So why isn't this one happy then?
- The fellowship of the ring
- to another king
- Paste.
- An uncopper.
- Ah, incorrect integer value for available copies.
- Okay, we can't say that they don't have an available copy of that book.
- In the way that our database is set up, available copies has to have a number.
- So we can get around that as being an issue by saying available copies is
- required. it.
- Now when I put that up there and I refresh this page here,
- if I try to submit it, it says please fill in this value first.
- So if I fill in that value, we then get the correct value.
- And if I was to get rid of my die command
- and do that,
- I come here and in there we
- get
- Perfect. All working, all submitting, all saving.
- I'm going to stop the video there.
- I'm going to have a quick think and look at how I could do the encoding in a
- different way. I'm not happy with the base 64 of it.
- I want it in a nicer, cleaner way, where if we were looking into our database, we
- could see the authors to see where the similarities in the authors are and that sort
- of thing. I will jump back on in about five minutes when I've had a little bit of
- play and figured something out.
- okay so literally seconds worth of um looking and i've realized
- what to do or learned what to do i should say rather than base64 encoding or
- javascript encoding what we can actually do is tell mysqli through our connection
- to encode it for us so i can say dollar sign connection
- and what I want it to do is real underscore escape underscore
- string. And what that's going to do is it's going to take any commands, anything so
- far we've given it and remove any unwanted characters.
- So I've already had a test and you can see it's worked on those two there, but let's
- go in and let's have another look at something else.
- So Bob, Airverse,
- WeAreLegion. are legion
- we are legion we are bob denisee taylor there we go
- got these elements in place here signed edition is all three books on amazon and i'm
- just going to put in bob reverse there so you can see that let's check in 43 copies
- add book and in my database then refresh that you'll see that
- We are legion, we are Bob is there, Bob-a-verse is there with the little symbol in
- place already there. So if I scroll all the way back, you can see it's been escaped
- and they've included it there.
- Just to do another demonstration,
- let's see,
- ready player one, and it's got a comma in its
- description already. let's add in four books and if I refresh
- this we've got ready player one and the comma is already there it's able to handle
- all of those elements directly and as expected my book pictures are all starting to
- appear in a much better way as well there's a large icon so you can see the Martian
- you can see the original books Lord of the Rings the Harry Potter book and the ready
- player one and we are Legion books already, all of those pictures being directly
- downloaded so that we can use those within our system.
- Thank you very much for watching again.
- I know this one has been a very difficult video, a very difficult video for me to
- record as well, going back and forth and all these different pieces.
- If you had noticed the timing, you probably won't because I generally put myself
- over the clock. I did start this around about 11 o'clock this morning and it is
- currently quarter to six. It has been a very long slog.
- Do let me know if it's too confusing.
- I'll try my best to break it down into smaller sections.
- I will re-go back over and re-record elements.
- I want you to understand this.
- I understand that you have to deliver this to your students.
- It's not me sat in front of them.
- They're not watching these videos.
- You have to be able to confidently show them what you are doing.
- So if you need any more instructions, any more guidance on it, then please do reach
- out and contact me.
- Thank you very much. Hopefully you have a nice two weeks.
- There's not very long left in school here now.
- Hopefully it'll all be done soon.
- Thank you.