Class Checkpoint

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
  1. In today's session, we're going to be looking at Google Books API integration and
  2. how we can use Google Books to pull in information on the different books we want in
  3. our library. It's going to use the same form of search as we use with our search
  4. bar, Ajax form, which will then search through Google Books API and allow us to add
  5. the information to our database.
  6. We will create a small form that will allow us to change some of that information.
  7. So if we pull through the information about a book, we want to update a little part
  8. of it. We're going to include a form there so we can do that as well.
  9. Okay, let's get into it.
  10. Okay, so as you can see, I'm back on my student desktop and I've got Parkwood Vale's
  11. website open.
  12. From here then, I've already logged into my account and what I'm going to do is open
  13. up the admin section. On this admin section here, this is the part we're going to be
  14. looking at. When I was talking about APIs just now, I was talking about what happens
  15. here. So by the way, I've been Harry Potter.
  16. You'll see as it's searching through, it searches through all the different Harry
  17. Potter books. It shows us how many stars they have and how many people have rated
  18. that book. We also have in place who the author, oh, the name of the book, sorry,
  19. who the author is it's ISBN, it's publisher and a small description of what the book
  20. is about. All of this information here is pulled through using same sort of
  21. Ajax we used last time for our search up here for this search element here
  22. and it's not going to, well it is going to our public site, it is going to a page on
  23. our website but that then searches using a special search command Google APIs
  24. itself. So if I
  25. were looking two seconds ago at say the prisoner of Azkaban in this long
  26. mess here you'd probably find the prisoner of Azkaban there's the Chamber of Secrets
  27. the psychology of Harry Potter there are lots of different elements
  28. and they will pull through in different ways now this here what we're
  29. currently looking at is called a JSON object it's a JavaScript object notation a way
  30. of passing information from one server to another server, from front end to back
  31. end, to make sure that the information gets passed in a way that can be used by lots
  32. of different applications.
  33. If I take all of this JSON code and I go to a JSON parser website,
  34. this first one's just as easy as any, and I paste it there, what we will see
  35. is that our object has 10 items within it.
  36. Each item gets a kind, ID, e-tag, and link to it.
  37. Get rid of this advert for a second, and let's actually just jump down to full
  38. screen.
  39. With all of that information in there, we have the authors of the book, the
  40. publisher, when it was published, the description of it.
  41. So that there is the ultimate Harry Potter philosophy.
  42. We're not interested in that one.
  43. Here we've got Harry Potter and the Chamber of Secrets.
  44. Good starting point, and if I went back to Parkwood Vale, If I scroll up, Harry
  45. Potter and the Chamber of Secrets.
  46. J.K. Rowling, Bloomsbury, four stars, three.
  47. In here, J.K. Rowling, Bloomsbury, and if I look through, average rating three and a
  48. half, so I probably rounded that up to four, and the rating count is three.
  49. If I go back over to here a second then, we can see that picture is of what looks
  50. like a cartoon, an animated version of Harry Potter.
  51. you will see that we get image links.
  52. We've got a small and a thumbnail and if I hover over it it's exactly that same
  53. picture even down to the little page turn there.
  54. The reason for all of that is that it was exactly from this section that I found
  55. that information about Harry Potter.
  56. So that's what we're going to be looking at today.
  57. We're going to be looking at how we can use something like Google's API here to pull
  58. in that box information based around that search field that we have here.
  59. The first thing we need to do with our site is set up so that when we are logged in
  60. and we are on the my account page here we have that ability to get to an admin
  61. section if we are admins. So there's my admin section.
  62. So I'm going to go ahead I'm going to open up Dreamweaver
  63. and I'm going to make sure that UwAmp is running so let's check down here yes it is
  64. already running and there is my site.
  65. So let's close down these previous elements that we've got included and let's get
  66. started with this. I'm gonna start off by finding my header and in my
  67. menu system down here, then after my search bar, where I've got my account, this is
  68. where I need to make some sort of changes.
  69. So I want that now to change from just being a simple account button to being a
  70. dropdown menu. So if I go here and log out a second, I can show you there's the
  71. account button.
  72. And when I'm logged in, there's the account dropdown,
  73. to it.
  74. The way I'm going to do that is I'm going to put in place some checks here.
  75. This element is being shown, this ul section here is being shown to the user because
  76. they aren't logged in. So I want to put in a PHP tag.
  77. It's going to be an if statement and let me just put a curly bracket there and I'm
  78. going to close that a second and just go to the other side of my ul tag and make
  79. sure I close off that curly bracket.
  80. Now this if statement is our condition that we want to know whether or not our
  81. user's logged in. Thankfully we should have at the top here or we haven't yet but we
  82. should include our session underscore start
  83. so we can ensure that we've started our session in
  84. place. Now every time we load our page our session will be there and what we're
  85. going to down here is we're going to check to see if a session piece of data has
  86. been set. So I'm going to say if is set and that is going to be
  87. dollar sign underscore session
  88. and I want to know if session and we're just going to use email has been set.
  89. And I'm going to say that if that is set is equal to false so it hasn't been set
  90. show this menu option here our login screen let me save that push my
  91. header up and let's go to localhost
  92. now
  93. that's not showing anything so I'm gonna guess that if I went to forward slash
  94. account I am logged in it's come up here sessions already been started twice we can
  95. ignore that for a second don't worry about that error at the top there but I am
  96. already logged in so that's why it's giving me error that's why it's not showing
  97. that section I'm gonna say that if it is set else
  98. then what I wanted to do is display for me my
  99. drop-down menu so let's just chuck in a closed PHP tag here to make sure that
  100. we don't miss anything as we're going along so next up
  101. then what we're gonna do is use this else statement to put in an unordered list like
  102. we have here but this time around it's going to be more focused on setting up our
  103. drop down list for our nav items so i'm going to copy our unordered list here
  104. elements and just paste them below a second it is still part of our nav bar it still
  105. has its margins it still has everything in place we want it to it still has an li
  106. list item for nav item the main difference being that this one is going to be a drop
  107. down type so i'm going to put in drop down
  108. And our A class element here is going to be a class with a drop down
  109. toggle in place. So let's see if toggle's there.
  110. It is. And happy days. Now this is going to go to nowhere.
  111. So I'm going to use a hashtag there for my ahref, which I'm going to put that in
  112. place. It is going to be slightly different though, because it has a role.
  113. It's role is a button for us. as well as having our role of button
  114. we need to tell it that it's a data tag of bootstrap and it is a toggle element
  115. now this toggle is going to be called drop down itself and
  116. that's going to put that all in place so i've got my x elements set up
  117. the last part i need to do is give it an area
  118. and it is going to be expanded and our expanded here is going to be false meaning
  119. that it's not already drop down when we start now all of that's in place we
  120. just need to give it the unordered list elements that are going to go underneath
  121. where our drop down class is so our class in this element then is going to be called
  122. drop down because that is what everything is linking to it's looking for a toggle
  123. drop down it's a type of drop down it is working with our drop down it is going to
  124. be a class of drop down hyphen menu and underneath here then we will have our list
  125. items just like we standard have at the moment our list items are going to have
  126. their own classes so an a class that is going to be set as a drop down item
  127. and there's my item and let's just end that a tag a second there just so i
  128. can copy and paste these what we're going to have then is three of these.
  129. We're going to have one for my account to get to the account page.
  130. We're going to have one for admin, if they are admin, and we'll check that a little
  131. bit later on. And we're going to have one here then for logout.
  132. So if you are logged in, you can now log out by going to this page.
  133. Each of these are going to have a type of ahref to them.
  134. So, ahref equals, and they're going to go to the different pages.
  135. Now, I'm not going to lie to you, this is going to be the third time I've done this
  136. actual video. The second time I did it, it worked perfectly, but I recorded my wrong
  137. screen. so this is going to just go to account happy days i'm all okay with that i'm
  138. going to do forward slash account this is going to go to forward slash admin and
  139. this is going to go to forward slash log out now i have
  140. created these admin and account pages in my previous videos which were completely
  141. useless but never mind so let's bring these assets down i'm not interested in those
  142. let's expand these you can see here is my logout page what i'm going to do is i'm
  143. going to save this and wherever my header is gone it should now be alphabetical
  144. order and header there we go let's put that up so that's in place on
  145. my logout page then this is one that i did earlier bit of a blue peter moment let's
  146. check that in place let's talk you through what it's doing it is starting or it is
  147. destroying the session so there are no longer session details in place and it is
  148. just redirecting us straight back to the login page our admin account then our admin
  149. starts our session. It then checks to see if the session is empty and if it is it
  150. redirects us away from it. It includes our header information so we can do our
  151. connection and it does a test to see if we are the only person who is set as admin
  152. and if we are the only person who is set as admin then it is going to redirect us
  153. away back to the login page. Oh sorry let me try that one again.
  154. If we are admin is fine. If we're not admin so if the records don't equal one then
  155. it redirects
  156. brings us to this form page here.
  157. Let's create this form page. What I did was I copied the contents of my account
  158. page. It all looks very similar.
  159. And all I did was I removed the additional search that I don't need to do.
  160. I put in a form. That form there has come directly from my header section.
  161. It is the header section here.
  162. If I scroll down to it, if I can find where I've got it to, it is this form here my
  163. search and live search were then created corrected to be admin search and admin
  164. results and i removed all the elements the styling around this admin search that put
  165. it in that top corner and what i get is a screen that looks like this so i'm
  166. logged out here but it's giving me a bit of an error it's saying sessions already
  167. started it is a notice and i'm take you through how to fix that in a second.
  168. I'm going to log in and that's going to
  169. bring me to my drop down. I can go to my admin page which has the ability to search
  170. through my existing books
  171. but nothing else aside from that.
  172. If I come back here then you can see the H2 for my heading and my form to search for
  173. that. Now I said I'm going to show you how to get rid of this error at the top here.
  174. What this is saying that session has already started.
  175. It's been started on the headed page on line two.
  176. So it's going to ignore the session start.
  177. I'm going to go into UBank.
  178. I'm going to click on the little folder here, the same one we used when we went in
  179. to find the mail elements. But this time around, I'm going to be looking for error.
  180. And I'm going to search through and I'm going to look through until I get to the
  181. very end here and we get to the error handling
  182. And the error handling section we're looking for, let me just close that because I
  183. know I'm on the right section then.
  184. If I scroll down to it, states that display errors is on, display
  185. startup errors is on, log errors is on as we keep going through.
  186. And I think I passed it actually.
  187. There it is. It is this line here.
  188. Error reporting equals E all. If you have a look, it's actually line number
  189. 445.
  190. says is that it wants to show all errors warnings and notice in is notices including
  191. coding standards well we're not too worried about some of our notices so we're going
  192. to go for the second option here which is e all except which is what the tilde
  193. symbol means notices show all errors except for notices so I'm going to highlight
  194. that section there just copy and paste that into place and file
  195. and save and when i file and save that and close this you up is going to have to
  196. cycle so it's going to stop and start again
  197. let's just stop it all it's all completely stopped start it
  198. all again start it all back up and running all happy if i refresh this
  199. now
  200. we get the same page but no longer with that notice error at the top corner there
  201. so with that done what we're going to do next then is code the back end search
  202. because at the moment when we search for anything it's searching through our library
  203. book and we don't want that we want to search through google's library books i'm
  204. going to go back into dreamweaver then and i'm going to create a new file on the
  205. side here and call it online search.php.
  206. Now, unlike with a lot of our files, we don't need a connection to our database
  207. here. We also don't need to start our session here.
  208. This is a unique file in the fact that it doesn't really matter what comes before
  209. it. What I want to do is capture a response from Google.
  210. So I'm going to put in my response variable
  211. equal to and this is a bit of a strange one but it's a function called file get
  212. content
  213. get
  214. Contents and that will get the contents of anything that I give it as a URL
  215. And that's where I'm going to put in place and I'm going to use single quotes for
  216. this that google books link So HTTPS and it is www
  217. .google
  218. Let's make sure I got that right.
  219. APIs.com forward slash books, because that's the element we're looking at on their
  220. APIs. Forward slash version one forward slash volumes.
  221. Now, I've got those volumes there in place.
  222. I'm going to press the question mark and put in a queue for my get command query.
  223. And I'm going to say equals in title, which is what I'm searching for first of all.
  224. semicolon and then I'm going to tag onto that my get string so underscore get
  225. and in there I'm just going to simply put name because it's the name of the book
  226. that I'm interested in.
  227. I'm going to print out a second underscore r my response
  228. so you can all see how that looks
  229. when that comes back in and if I save that and I know the online search I was about
  230. half an hour ago when I first did this video through then we're going to stop there
  231. for a second while online search
  232. Now for you that's going to be about 2 seconds different James Bond is coming back
  233. and finished the video It doesn't like something different So, so far then we have
  234. created our drop down for our account Now the reason why it's failed on that request
  235. is that James Bond is actually two terms that my browser puts this dollar sign
  236. percentage 20 in place for. If I remove that and just put in James, I'm logging in
  237. page, I get my dropdown again in place.
  238. If I put in my search is there, that's fine.
  239. Admin search is here.
  240. That's fine as well. The name element should be to finish.
  241. I thought I had an element like that.
  242. Part two will continue in a moment.
  243. Encode function.
  244. Now that's giving me some sort of indication.
  245. something's not right because that should not look like that url encode
  246. and i want to url encode this section here
  247. okay so there's that there before we go too far
  248. let's copy that let's echo that and see what
  249. exactly it is doing just so that we are fully aware of what we're getting
  250. HTTP Google Books API.com James.
  251. Ah, did I do something wrong? Did I do HTTP?
  252. I forgot to put the S in place.
  253. It doesn't like unsecure connections, I don't blame it, but let's go here, let's put
  254. that up and refresh it.
  255. And there we go, we're getting all of that information back.
  256. And actually, with that in place, I can even go as far as putting in bond as a space
  257. URL in code element would take care of those spaces.
  258. If I just show you again with Harry Potter
  259. and search for that, it's brought back all this information about Harry Potter.
  260. We've got our title here. Let me just copy this and paste it.
  261. And this is what we're getting back.
  262. It's not coming back as pretty as that, but it's still the same information.
  263. If we have a look, The first title coming through is The Ultimate Harry Potter
  264. Philosophy, like we saw earlier.
  265. In our books, our volumes, if we go title, here's our first title, The Ultimate
  266. Harry Potter Philosophy. It's exactly the same premise.
  267. Let's go back into here then. We no longer need that echo.
  268. We found out my issue. My issue is the fact I forgot the S in my secure connection,
  269. and that's in place there. that file get contents is stored that contents in there
  270. but that contents isn't really that usable for us what's come back is our json
  271. string thankfully php has its own json functionality so json
  272. underscore decode and i want to get the response from
  273. what i've been given now if i decode that and let's fix decode
  274. there save that and push that up when i refresh it
  275. i now get a standard class object which i can actually for loop through
  276. so my response is there and i can do for and let's see each
  277. for each element in json decoded response let's give it those there
  278. as dollar sign kind to with.
  279. Now inside that section there I'm going to set up the details for each of these
  280. books so I'm going to say $deets as my details array equals
  281. JSON and I want to again encode this time so I can look
  282. through it in a different way and I want to JSON encode my response.
  283. My response is going to be set up with my books element.
  284. So I'm going to say there I want book is equal to an element and my book
  285. element is its own array and this will all hopefully make a bit of sense when I put
  286. it all into place for you in a second.
  287. So what I'm doing actually, let's talk you through it, it's a bit easier at this
  288. point, is I'm looping through each of these and outputting its kind.
  289. I'm creating a new array which is a JSON encoded array and that array contains a
  290. starting point of book so it's going to have lots of different books in place.
  291. Inside that book we are going to have an array of objects so let's bring this up to
  292. here there we go and inside the array of objects here we can put in different
  293. things. Now we're interested in title which is the name of our book.
  294. That is going to be our kind which comes from this section here and we're going to
  295. say that we want the volume
  296. information and the volume info I'm looking for is title now if I jump
  297. I can do a comma would be helpful but if I jump back over here a second so we're in
  298. kind and then we have our different items and inside our items section here
  299. we have our different kinds and we have all of our volume information is
  300. here so our volume information starts as its own class that has title in place
  301. subtitle and so on so I've got in place my title there I'm going to say
  302. my image that's the picture that we are going to use as our jacket image is going to
  303. be from our kind and then it is going to be the volume info again
  304. and this time around we're going to go to image
  305. links and we just want the thumbnail now not all books come with a different sized
  306. thumbnails so I'm just using the standard thumbnail facility there I don't need that
  307. at the moment I can just tap that in so you can see it clearer
  308. I'm gonna say that it's author or authors given the fact that there could
  309. is set to the dollar sign kind again.
  310. We're going to do the volume information again.
  311. And this time around, it's going to be authors.
  312. Now, that could come back blank.
  313. That could come back that there are no authors whatsoever.
  314. So what we're going to do is check to see if that is equal to zero, or if it's
  315. empty. And if I open up a bracket here, and I say that authors
  316. doesn't equal null, I can use what's known as a tinary if, so
  317. an if function in one line, to copy that information and put that there.
  318. The else within our tinary if comes in the form of this semicolon.
  319. So what this tinary if is saying is if that
  320. authors section doesn't equal null, then set the information to what's in the author
  321. section, otherwise set it to zero.
  322. So I can work with it later and I can understand that it's a zero, so therefore
  323. there's no information there. And I could probably put that in for a lot of our
  324. information, because not every single book is going to have authors on Google's
  325. site. Now, every book's going to have ISBN, publishers, categories, all the other
  326. bits and pieces aren't always going to be filled in from Google.
  327. So I'm going to copy that and paste that there.
  328. After authors, what I'm going to do then is put in my ISBN.
  329. I want the ISBN number, which is coming through from the volume information again.
  330. And this time it is going to be in the industry.
  331. And it is the industry identifier.
  332. and that's that set in place and again if it's null then give us null otherwise give
  333. us the industry identifiers I'm going to go on to the next line again then and I'm
  334. going to put in place the publisher and what I'm doing is taking from the
  335. complicated google side of things through to my basic easily understandable for me
  336. side of things and this time around our volume information we're looking for is
  337. publisher and I'm going to do the same thing here so publisher
  338. and that's going to say zero if there's nothing to be seen and let's put the next
  339. one in place for category and again
  340. just volume information for category making sure that's all in place the only
  341. difference being that it could have multiple categories so in google that is coming
  342. through categories. Now you're probably at this point looking at this going how do I
  343. remember all of that? How do I know what's going on?
  344. That's because in this section here, let me just get back to the right window, all
  345. I'm using is these information points here.
  346. So in this section here my volume info is there.
  347. I've got title, subtitle if I wanted it, authors.
  348. If authors was empty that's it'd be a zero.
  349. I've got publisher, I've got industry identifiers, and it's coming through and
  350. pulling through my industry identifiers.
  351. It's got categories. All of this information is being pulled through, and I'm just
  352. looping and putting the different information in place.
  353. Now, I'm going to do the same thing again with description, so copy that, put that
  354. there, change it to description.
  355. And this is going to build up an array for me of all the different books that google
  356. are giving me so let's see description and
  357. we've only got two more so i might as well go through all of them number of rating
  358. and average rating so in there then i'm going to say volume information
  359. rating count rating
  360. count and again
  361. ratings count that's I'll leave that ratings count that's how many
  362. people have given it that star rating and then the last one here is going to be
  363. average rating so instead of ratings counts there there and there I'm gonna say
  364. average rating
  365. Have I spelled rating right there?
  366. Who knows? We'll find out. Now, that should populate my database.
  367. Oh, sorry, not my database, my array with my information that I want.
  368. So let's just see. And I don't want that there.
  369. I want that there.
  370. So this square bracket here, this square bracket ties in with this square bracket
  371. here for an internal array.
  372. is called book and then we got our JSON array there.
  373. That's going to loop through each of those and all I'm going to do is come down here
  374. and simply say print and what do I want to print?
  375. I want to print my deets and actually I want to print our deets.
  376. save that i do need this back now to be able to push that up and
  377. let's refresh this
  378. and that hasn't quite gone as i expected so let's have a look at why
  379. that's why because even though it comes through and it's a kind we are looking for
  380. the items within that kind element there.
  381. I didn't put the items in place.
  382. So what we need to do is say that when we've decoded it,
  383. start inside items.
  384. And if I save that now, and I put that up,
  385. what we'll get when I refresh it
  386. are all of our Harry Potter book informations for our 10 books within that section
  387. there. Doesn't look very pretty, doesn't look like much at the moment, but we're
  388. going to go and stylise that next.
  389. going to do that is we're going to loop through this details array.
  390. What we're going to do though is come out of PHP.
  391. So the next couple of bits and pieces are going to be pure HTML just to give it its
  392. style of how we want it to look.
  393. So I'm going to say div class equals and again this is going to be
  394. following the same MDs styling that we've done previously.
  395. So I forgot about PHP. There we go.
  396. Div class MD12 and let's end that div there.
  397. Now inside there I'm going to put in a row.
  398. Div class equals and this is going to be row with a
  399. margin to the top of two.
  400. And then I'm going to put in place some information based around our box.
  401. realistically i want this to be going on while it's looping through each of these
  402. elements and they're just hidden in the background there so i don't want to end my
  403. php there i do actually want my php there so i don't want that end of that loop tag
  404. there i'm going to come out of there entirely i'm going to come down below here then
  405. put in place another php tag just so that it ends that loop tag there
  406. and that should give me all of that so what it's going to do for each
  407. one of these is it's going to create a column of 12 with a row inside of it and give
  408. me some information inside of there the very first thing I'm going to do is put in
  409. place my div class and it's going to be a row for my book image my jacket
  410. and it's going to be not row sorry it's going to be column of md3
  411. inside there we're going to be using an old-fashioned image tag
  412. with the source because we can't use webp images until we've
  413. actually captured them i want to in there php
  414. echo out and i actually want to echo out my image information
  415. my kind thumbnail that we've got from
  416. and echo out that kind thumbnail and close that image tag.
  417. Now that will put in place my image and set it to however it is.
  418. What I do want to also do just very quickly, let me check.
  419. I haven't finished my PHP tag off there.
  420. Close that off. Brilliant. I'm still inside there.
  421. I'm going to say width equals 100% on my picture, just so that my
  422. picture is taking up all of its parent space that
  423. Now the next section there is going to be a div tag again, is going to be that
  424. class,
  425. col, md, and this time around it's going to be a 9.
  426. And I'm going to put that in place and terminate that.
  427. And I'm going to start structuring the information based around my book about what I
  428. want to have in place. So a heading number 4 is going to be put in place for the
  429. title of my book. and again I'm just going to use PHP tags to echo
  430. out. Now I should be able to echo to make things a little bit easier
  431. for me possibly my details but I'm not going to.
  432. I'm going to stick with what this is and echo that title and
  433. then end that tag and that's there.
  434. Just for a second let me save that and let's put
  435. refresh and see how it looks different now, if at all.
  436. That picture is huge, but it has the text there.
  437. Another huge image with the text next to it.
  438. So let's remove this width a second just to see how that impacts
  439. upon its usability.
  440. Okay, so we're starting to get a bit better structure there.
  441. Now, I'm going to put in some other bits and pieces.
  442. I don't necessarily need all of the information in place, but just some of that
  443. information. What I'm going to do next then is put in a p tag and I'm going to
  444. simply inside my p tag there, echo out some of the information that I want to
  445. display that would be handy to know at that time.
  446. So let's do a PHP tag and echo this kind volume information
  447. and I do want to echo out my author
  448. and I can end that
  449. PHP tag there I'm going to put in a break tag so a simple
  450. br tag and then I'm going to do a similar sort of element copy this paste this here
  451. but instead of author what I'm actually going to is put in place,
  452. well, I'm gonna put in place the ISBN.
  453. So let's go up to here, have a look.
  454. I got my industry identifiers, let's copy that,
  455. and paste that here.
  456. Now if I save that and put that, let's see how that looks.
  457. Ooh, it's not happy with something on line 31.
  458. line 31 echo there we go and that's because I copied the
  459. whole of my TNRF I don't need the whole of the TNRF I just need to have that
  460. fresh Harry Potter array array right okay so we're saying array array on these
  461. elements here that means that we have been given an array but we're trying to print
  462. it as a string and it doesn't like that but if I just simply said at
  463. Programmatically, that means the very first position, it will print the first of my
  464. records. So now, I get Harry Potter, I get J.K.
  465. Rowling's. It's not happy with something converting from a string on line 31.
  466. Okay. So what this is saying to me, then, is that even though it was an
  467. array, it hasn't found anything.
  468. so if I was to remove that assignment and I
  469. was to refresh this now I get Harry Potter an array or JK Rowling sorry an
  470. array but it's telling me that if I print underscore
  471. r because I wasn't happy two seconds ago with how I echoed that out
  472. let's see how it does it if I printR it.
  473. And even though it's an array, it's given me other options.
  474. So inside of the array, we have its type with ISBN and its identifier.
  475. So if I was to go to array position zero and
  476. put that, we're now given, are we looking for the type ISBN
  477. or its identifier? Or realistically,
  478. identifier. So if I did identifier there instead and I change that back to
  479. an echo, we now get
  480. that correct information. And as we go through, it's there for all the different
  481. books, depending on the different titles.
  482. It still tells us the ISBN numbers for all those different elements, all those
  483. different books.
  484. As well as the ISBN information then, it would be handy to know who the publisher is
  485. and we're going to do the same thing as we've done here so we're going to have a
  486. break here a br and then we're just going to copy this section here and drop the
  487. publisher in instead of the author now i don't think publishers
  488. are ever done on a array so we can just do that as a single publisher element and
  489. let's drop that up
  490. and we've got the publisher as well and the very last thing that i was going to set
  491. out is a small description of the book and I don't want to do the whole
  492. description. So when I do the PHP tag here and I do my echo
  493. for my description,
  494. what I'm going to do is actually use a substring, a
  495. substr of my
  496. kind, volume, and this time I want the description.
  497. and the substring I want, so let's see, there's that substring there,
  498. should be from position 0 to position 100.
  499. And what that means is, take the first 100 characters of my description.
  500. And yes, it's characters, not words, so it would sit in the middle of a different
  501. section. So on line 33, undefined function substring.
  502. What have I gone wrong there? I've done string wrong.
  503. I always tell students off for doing source wrong.
  504. I've done string wrong. It's sub str for string, not srt.
  505. And if I refresh that now, we get the first 100 characters.
  506. So just to make that a little bit nicer looking, what I will do is do dart and
  507. speech marks 1, 2, 3. Just so you can see those ellipses show you that there's
  508. something else in place after it.
  509. now with all of that in place if i refresh this we get our little elements there and
  510. i can include if i go back to my
  511. search element i should have in here
  512. my star rating let's copy this code
  513. onto my online search and paste it below.
  514. Now this is PHP code so I will have to put it inside a PHP tag again.
  515. Star rating should be five. Star rating this time around is going to be from our
  516. ratings section.
  517. Let's see I have volume average rating.
  518. Let's copy that.
  519. and in my rating section here then I'm going to paste my average rating
  520. and that rest of this function should work in exactly the same ways it
  521. does on my other page so what that's going to do is put those spans in place which
  522. when we first see them we're not going to see the spans those spans are going to be
  523. invisible because they are not linked correctly.
  524. They don't have their referenced elements.
  525. But when we put it into our actual admin page in this section here, then
  526. we should be able to see it.
  527. So I've gone through, I've set up that online search.
  528. Now all I've got to do is send through information to change what is inside my name
  529. element.
  530. On my admin page then, and actually it was on my footer element
  531. within the admin search so live search on search there
  532. admin results we don't want to do live search for search we want to do
  533. live search for online search
  534. this time around and q equals this true okay
  535. it's not going to be query it is going to be name
  536. equals that. If I put that up on my footer, that should allow me to do
  537. my admin search.
  538. That's searching my database.
  539. That's still searching my database.
  540. Let's see what's going on here and zoom out again.
  541. I will zoom back in so I can go through it, but it's just so much
  542. my search I swapped the wrong one so let's go copy
  543. paste cut paste save
  544. and put that up so making sure you're on your admin search and you're making it
  545. change into the online search rather than your normal search I've just put that up
  546. then let's refresh this page a couple of times harry
  547. potter and the Deathly
  548. Hallows.
  549. And that's searched through and it's found me lots of different versions of Harry
  550. Potter and the Deathly Hallows.
  551. It's got me all of these different versions of it based around the publisher
  552. details.
  553. We've got Bloomsbury Publishing in place there, Bloomsbury Children's Book there.
  554. We haven't quite spaced out nicely.
  555. Let's go back to our online search here scroll down and
  556. let's put a break line in there so that should go to the next line now this
  557. didn't seem to be doing anything for me at all I wonder why we'll have a look at
  558. that in a second let's first of all put not enough but a online search back up and
  559. re I don't know why refresh is an ajax search it shouldn't need it Harry Potter
  560. there we go and we're starting to get some black stars in place.
  561. Harry
  562. Potter
  563. and the Deathly Hallows is coming back there.
  564. It's given me three black stars for some reason.
  565. I'm not getting any gold stars, but it is.
  566. Now I'll give you my description on my second line.
  567. Realistically, I didn't need to do that.
  568. I could have that set to a much higher number if I wanted to and put that up.
  569. And just to
  570. that changes it's now giving me 500 lines of it rather than just 100 lines of
  571. it or 500 characters not lines sorry but let's tackle this gold dot element then
  572. so um let's see star is five star rating is kind
  573. volume average rating i wanted to round this up have a look at a second
  574. four star rating is zero to, well star rating is less than, there we go, and
  575. it's got checked there.
  576. Did we do something special with checked on,
  577. where did we put the CSS for checked?
  578. Okay, checked is on our header, so it should be in place, goldenrod.
  579. Let's go into inspect,
  580. and they are stars they are not checked stars if I set it to
  581. check it does go gold so it's not the CSS that's a problem it is the initial PHP so
  582. online search star rating what do we get
  583. let's have a look. Let's echo star
  584. rating and see what we're actually getting.
  585. Nothing by the looks of it. There are no numbers coming back whatsoever.
  586. Inside there, inside there, inside there.
  587. We have our stars. I don't know why we never have three of them that's a bit strange
  588. it should do five of them but our average star rating
  589. isn't given us anything um let's go
  590. star and put that up um online
  591. search
  592. okay star is still giving us nothing after it fair enough
  593. in there then
  594. volume info average rating let's have a look here we want
  595. items and then we're in volume info here and
  596. average rating should be there.
  597. Okay.
  598. Let's just have a quick look at these books a second.
  599. I'm going to go print underscore r dollar sign
  600. kind volume info.
  601. Okay,
  602. save that, put that up. So that's gone to there.
  603. And now if I refresh this, oh, shouldn't have done that.
  604. Harry Potter and the Deathly Hallows.
  605. That's giving me all of this information about Harry Potter and the Deathly Hallows.
  606. I've got the title, publisher, published date, identifiers
  607. my ISBN number that's fine no it's not content we've
  608. got our thumbnails from our images there it is and small thumbnail
  609. why is that not
  610. okay so average vision should come before image links reading modes text
  611. print book, not much sure.
  612. Let's get rid of that.
  613. content version
  614. Pause this a second.
  615. And volume info should have industry identifiers,
  616. reading modes, categories and average rating.
  617. Average rating does exist there.
  618. But they're still coming back with nothing in place there.
  619. So, star rating equals kind volume info average rating.
  620. For each of the average ratings
  621. is less than the star rating
  622. that's baffling me i honestly don't know um why is it coming up and it's not got
  623. volume info star rating even when there's star ratings included if i was just to
  624. spin this around a second and make it so that they're all three star books let's
  625. just double check the star rating element is working and Deathly Hallows yes they're
  626. all three star books and in fact actually they've gone up to a four star they should
  627. have five there equals five that's going in once beforehand so perhaps
  628. star rating
  629. minus one
  630. No, that's coming out fine, so star rating should definitely be just SR.
  631. plus one, not plus 10, plus one would be
  632. enough.
  633. That should then at least bring us to our...
  634. Nope, it doesn't want to do five star, whatever I do.
  635. Strange.
  636. Dollar sign s r.
  637. Dollar sign s r should have come from there.
  638. No, I'm gonna remove it from there.
  639. Tackle it later. So we've got that there.
  640. Now, all of that is in place. All of that is set up so that when I do search for a
  641. book, and now I won't have any issues.
  642. I didn't put it, did I?
  643. Let's try putting it correctly.
  644. And now when I search for a book, it's gone there.
  645. That's all perfectly fine. What we need to do is we need to have an element now that
  646. when we click on to add a book, it passes this information to our ad book page.
  647. We haven't created our ad book page yet, but we will do.
  648. And the way we're going to do that is we're going to utilize this deets array that
  649. we set up earlier.
  650. It wasn't just for the sake of it.
  651. It wasn't just doing it to get you to type out a lot of code.
  652. What I'm actually going to do is, outside of my p tag,
  653. create a button, which is an
  654. ahref, which will take me to my ad book page.
  655. And I'm going to add some styling to it.
  656. is going to be type of BTN and it is a BTN primary
  657. and it's just going to simply say add book.
  658. Now when I put that in place and I refresh this
  659. and I search for Harry Potter and the
  660. deathly hallows, you'll see that we have this add book page.
  661. When I click add book, it takes me to nowhere because we haven't created it yet, but
  662. that is in place. We want to utilise and hijack, I suppose the term could be,
  663. the get command, and I'm going to say book equals,
  664. and inside here then, I'm going to put a PHP tag to pass that information across.
  665. And the PHP tag information is going to be my array.
  666. I can't simply print that array, but what I can do is encode it in a specific way.
  667. You'd have seen some sort of encoding using base64 whenever you've used
  668. the web and not realize what it is.
  669. Effectively this is going to be a very long string that doesn't look like much
  670. but the computers understand that it's encoded in some way.
  671. And what I'm going to be passing through my Base64 encoded section is simply
  672. my DEETS array so far.
  673. And as that goes through then, that should set up, and if I push that up, I'll show
  674. you what I mean. On here, Harry Potter and Deathly Hallows, and if I hover over it,
  675. it's not actually saying anything because I forgot the word echo.
  676. And let's push that up again.
  677. Deathly Hallows. Hover over it.
  678. And down in the bottom corner, in that long string, you can see that extremely long
  679. string there that has book equals, starts with
  680. EYJB29RLJP. That information can be
  681. reverse engineered to get it back to how we want it to look.
  682. So if I go in and add in a add book page, new file, call it
  683. addbook.php and
  684. open that up.
  685. And all I'm going to do to start with my addbook is simply php and print
  686. underscore r.
  687. And I want to print underscore r the get information.
  688. That is book.
  689. and we'll see how that looks. Let's end that PHP tag.
  690. Add book gets posted up. Now if I click onto here, we get this very long
  691. string.
  692. What I'm going to do is copy that string and very quickly jump into
  693. a base64 decoder.
  694. And if I paste that long string and decode it, you will see that
  695. it contains the information that we have set up.
  696. Okay, our average rating is zero.
  697. We had that issue two seconds ago.
  698. I'll deal with that later. I'll need to have a look at why that's coming through as
  699. zeros. But you can see the book title and all the other information that we have
  700. laid
  701. If I went back onto my site, and I go back to the previous page, and I put
  702. in Deathly Hallows, and I use a different, so the Gryffindor edition there, just
  703. to show that it's not just a coincidence, let's copy that, and paste it, and I
  704. decode it, it is now the Gryffindor edition, it is much smaller in detail.
  705. That's because I've passed that information through in a way that my computer can
  706. understand. I can go in and base64 underscore decode this.
  707. That will allow me to put it back in as standard edition
  708. PHP code.
  709. And now, when I reload this, it doesn't like something on that line.
  710. Why did it get rid of that? Dollar sign underscore get.
  711. There we go. it wanted it to be something in base 64 and it should have been and
  712. there it is and it's come back here as my json code if i want to get it further
  713. i want it to be json underscore decoded
  714. that's what happened okay base 64 thank you very much uh
  715. decode dreamweaver for making things more difficult than it needs to be and we
  716. have that in place. Let's put that up, refresh that and we know how our standard
  717. class object and we can use this information to effectively create
  718. a insert that allows us to insert this book's details
  719. into our library but also in a way where we can edit some of that
  720. information.
  721. What I'm going to do is have a quick pause, have a quick drink and then go now that
  722. form to add it to our database before submitting that book in place.
  723. Okay, so now we're at a stage where if I was to click onto a book and reload that
  724. book
  725. on that page there, let's put that page back up,
  726. it will give me all of those books details.
  727. I've declassified the books, I've decoded the book's details, I've Base64 decoded
  728. that long string, I've JSON decoded it back into its array format, and I'm printing
  729. it. That's not really that helpful for anybody, but we've got it there to look at at
  730. the moment while we structure the rest of it.
  731. The rest of our page then should look for something similar to our admin page.
  732. So I'm just going to hijack that, copy that, add book, and paste it all there.
  733. We do want our PHP session starting we do want to check if this session
  734. hasn't been set if so we're going to kick them back to that login page they should
  735. always be your first port of call so let's check those at the very top there then
  736. and i do want to include my set uh my connection details and my header details so
  737. i get my same layout now this section here where we're going through and we're
  738. querying our database don't really need it just yet we will but not right now and
  739. we've got our main our backgrounds and different elements in place.
  740. Perfect. Inside our container then, our rounded white box.
  741. We have our details here, our row for our ad book, and we're gonna be placing in the
  742. elements to show our book. Ad book to library is still a valid name, and we
  743. have this section here there.
  744. Let's just tidy up some of this indentation, especially with it being so large
  745. formatted. It makes it a bit easier to see exactly
  746. right there, there and there. Let's save that.
  747. And actually this print here, I'm going to take that print out of there and just
  748. inside here,
  749. PHP, and I want to print that element, save it,
  750. and let's put that up. When I refresh this now, it should look a lot more like we'd
  751. expect it to. It's got our basic elements to it.
  752. It's got the starting points. It's got the logout pages and everything we needed to
  753. have in place. Perfect. We now need to stylize how our form is going to look.
  754. We'll come back to where our form is going, what's happening with our form in a
  755. minute or two, but right now we're going to stylize some elements within it.
  756. First of all, I want a lot of hidden input elements.
  757. and input I'm going to put in type hidden
  758. equals hidden and some of these details are in place.
  759. Now actually let's think about this in a different way perhaps I don't want the
  760. inputs to be hidden just yet let's get that up from there so I can see this code a
  761. bit clearer and I'm going to put some different elements.
  762. So let's go for heading number two, shall we say, and let's say title.
  763. And underneath that, I want an input, which is going to be
  764. type equals
  765. text and its value is going to
  766. be equal to let's just decode this and store
  767. this in deets again deets equals that inside here and
  768. then what I'm going to say is php I want from
  769. deets
  770. a book and I want its title
  771. and let's close that off
  772. now I've done all that let's just push add book up again
  773. and see what happens empty inspect
  774. value is empty because I didn't echo.
  775. I still haven't echoed.
  776. Echo an ad book.
  777. Okay.
  778. Deets book title.
  779. Let's go print underscore r
  780. dollar sign deets.
  781. We're getting somewhere. We've got some information in place.
  782. Standard class book. It's got all of these information bits and pieces in place.
  783. What if I said Deets book?
  784. And title's only got... Right, okay.
  785. Let's go back. Deathly Hallows,
  786. a book.
  787. Online search. That definitely says title.
  788. Let's just check that up again, though.
  789. Online search.
  790. Title! We're getting somewhere.
  791. Let's go back to Add Book and let's put in title
  792. with an arrow.
  793. book except for the wrong page up and there we go okay
  794. so we're getting somewhere entirely let's drop that instead of print r to simply
  795. echo it and there's our deets are in place there they do need to be tabbed
  796. in let's check that back over there that's the
  797. value and let's go class equals form
  798. control. There we go. Title is now Harry Potter and Deathly Hallows.
  799. And let's capitalize that. So we can do the same element then with all of the
  800. different parts within our book.
  801. We can set all of the different titles to different sections that they need to be
  802. set to.
  803. I'm going to have to zoom out on this section here.
  804. I am sorry for that, but I cannot see it that clearly from there.
  805. So title is in place. I'm then going to go through and put it in as a paragraph tag.
  806. The next one up then I'm going to have is ISBN.
  807. And after ISBN, I'm going to do the same thing I've done here, but swap it.
  808. So instead of saying title, I say ISBN.
  809. Save it. And let's put that up.
  810. when I refresh it ISBN has come back as an array as we've seen previously we want
  811. the first position and we want the identifier
  812. let's put that up
  813. and refresh it and we get our ISBN number and we're going to do the same thing going
  814. all the way down now I got that as a title I could but it is label
  815. and end the label
  816. and have that there, put that,
  817. and it just gets rid of some of that spacing to make it a little bit neater.
  818. I'm going to do the same process all the way down, putting the different elements in
  819. for the different parts of the book.
  820. So label for author,
  821. and that's going to be identifier, author, and the
  822. first element.
  823. And let's put that. working our way through our different
  824. elements that we have passed it in deets which was set up here author
  825. is pluralized authors i want that to be authors and save
  826. that put that and refresh it and it's got our authors in place and we're just going
  827. to go through each different field making sure they're all in place one thing i have
  828. forgotten as i'm going down i do need to put
  829. This one here is going to be title.
  830. But the names should match what is set in my HeidiSQL.
  831. So HeidiSQL, let's have a look and open this up.
  832. In my books section, in my books table, I've got name, author, publisher,
  833. ISBN. So name here is going to be equal to name my
  834. book.
  835. name here is going to be equal to ISBN my ISBN
  836. name is equal to and let's double check
  837. our I've done it capital A for author just to make sure I got
  838. that in place as well and they're all going through each one at a time making sure
  839. that they are in place to match these sections here
  840. So next up then, let's copy these elements down.
  841. Let's go publisher, publisher,
  842. and again, just a single publisher,
  843. and it was probably lower cased.
  844. Just as I'm working my way through,
  845. refreshing the page just to check it's there.
  846. Bloomsbury, perfect. Next one up is description.
  847. description, nice and simple. That's what we call description and
  848. have its description as its content.
  849. There it is. It's got the full element there.
  850. I could set that to text area, but there's no real reason for it.
  851. And I'm going to come on to the next one as well.
  852. I'm going to say
  853. average rating, and that is going to be kept as rating, and it should
  854. be average rating.
  855. And I've got the rating element there, available copies, and jacket image are the
  856. only other two. If I check that up a second and refresh this, then average ratings
  857. come through a zero.
  858. Now, with available copies, that is going to be how many books we have or how many
  859. editions of that book we have.
  860. I'm going to say over here very quickly,
  861. available
  862. copies.
  863. And just make sure I'm matching that spelling in my name.
  864. copies.
  865. That isn't going to take a value because that isn't going to be coming from our
  866. element there. We can set our text to number.
  867. And when I put that up here, what that will do for me is when I go
  868. over to here, if I try and put words, it doesn't accept them.
  869. When I put in numbers, it does.
  870. I can do the same thing with average rating.
  871. And let me just go back over here a
  872. to number, and that's almost perfectly in place.
  873. We will put in place a hidden item, and our hidden item, I'm going to go to the top
  874. and put my hidden items all at the top for anything I want to hide, but it's only
  875. really the one. Input type is going to be hidden, and that is going to be
  876. for our jacket image, and what did I call it over here?
  877. I did call it jacket image,
  878. and say name equals jacket image and say value
  879. equals and just to try and keep it some sort of unified i'm going to keep it as the
  880. isbn for the book
  881. and
  882. have that there now if i was to save that and refresh this
  883. here. If I inspect it in my body, in my
  884. main container, or even my main up here, nope, it is
  885. this main here. Too many mains.
  886. If I expand this out a few times to get to my form,
  887. you'll see there's an input type and it's a text and
  888. And it's not actually showing my input type hidden, which is ironic.
  889. Did I put that up?
  890. There we go. Input type is hidden, and it contains my name and my values and my
  891. other bits and pieces. So they are all there correctly.
  892. If I was to submit this, I'd have no issues.
  893. It would submit to my database.
  894. It's not really giving me my image in place.
  895. So let's correct that then. I have here my row for my ad book.
  896. div class equals col md3
  897. again and that's where my image is going to be I'm going to do div
  898. class equals col md9
  899. and that is going to be setting up
  900. my form so So I want to tab that in and then everything
  901. inside my form all the way down to here, all of these elements need to be tabbed in
  902. as well.
  903. And I can end that div there and that can come back one.
  904. And what I'm going to do is you're going to separate it.
  905. So on one side I have my picture, on the other side I've got that image, all that
  906. text. And if I put that up right now and refresh it, we'll get the same thing.
  907. Oh, it worked this time, last time.
  908. If you remember, it filled the whole lot of screen.
  909. I had to put an image there first.
  910. In here then, what we are going to do is put in our image, its source, because
  911. again, it is not going to be in WebP, so there's no way we can use anything other
  912. than its source. And we are going to echo from our elements, from our deets, which
  913. actually are done before this.
  914. So I need to move my deets up here, and that should put that in place.
  915. Echo, there we go. I want dollar sign, deets as a book.
  916. and within the book if I open up my online search what did I call it I just called
  917. image nice and easy I want its image now if I save that and put that up
  918. and I refresh this everything breaks pretty standard really let's put that
  919. there and now nothing should have broken at least it just wouldn't show me my
  920. picture that's fine I can live with that I can solve that one as we go through
  921. it's book image deep book image should be there that's fine there let's bring that
  922. right back perfect we can get rid of that start time get rid of the end tag and they
  923. just save there
  924. amazing there right image online search
  925. deep book image image thumbnail there okay that should be fine because it did work
  926. on the other page as well um let's just go by here a second where
  927. i can see php ah already seen my issue before i
  928. even had chance i'd forgotten to php i just done the question mark
  929. he says with quite a lot of confidence because that worked for perfectly fine now
  930. when we've done it and set out in this way what it means is that if any of these
  931. bits of information need to be changed in any way they can be changed
  932. so for example this average rating there was zero I could put that back in as 4.5 I
  933. can say that there are 10 copies of this book that are available and there is the
  934. poster picture for it what I'm going to do
  935. is submit all of this information back to itself.
  936. I know that sounds strange, but in my form details, wherever the start of my form
  937. was, I do need to possibly move some things around with that.
  938. We'll leave it there for now. We'll possibly do it in a different way.
  939. I'm going to say that the action for this form
  940. is going to be set to itself. Add book.
  941. post method equals post.
  942. So when I submit this form, what it's going to do is try and send the information
  943. back to itself, where it got it from, and process it there.
  944. And all I've got to do is put in a check, a catch, to see if it
  945. has anything in its submit.
  946. So I'm going to say input type equals
  947. submit.
  948. I'm going to say that its Its value equals
  949. addBook.
  950. Its class is a BTN, BTN primary.
  951. And that's that.
  952. Let's put that up and refresh that.
  953. AddBook is our button there. I've got a bit of a margin on top of it, so I'm going
  954. to say margin top is equal to 2.
  955. Put that up,
  956. refresh, and we get that there.
  957. If I hit this button now, it's going to redirect back to the page I'm currently on,
  958. and it will get rid of all of this get string.
  959. And now I've got no information there.
  960. Exactly like I expected it to do.
  961. I hit that and it disappears because it's no longer in the get string and that's
  962. what I want
  963. what I'm going to do is go up to the starting section on my page
  964. and up here before I go into my deets or anything like that I'm going to check
  965. to see if dollar sign underscore post
  966. has set ISBN because I'm not going to be accepting any books that haven't got ISBN
  967. set in place. If it has got ISBN set, then we're going to do something
  968. different. What we're going to do is we're going to put in place an insert
  969. statement, so $SQL
  970. and I'm going to say actually rather than insert replace
  971. into books and I'm going to
  972. say what it is I'm giving it to replace into books so that would be
  973. name ISBN
  974. and all of these categories
  975. description,
  976. rating,
  977. and jacket, image, and available
  978. copies. So I'm giving it all of that
  979. information
  980. to use within its insert statement.
  981. Its values are going to be from our post.
  982. So 1, let's just do 2, 3, 4, 5, 6, 7,
  983. and 8. So that's 1, 2, 3, 4, 5, 6, 7, and 8.
  984. And each of these is going to be from $sign underscore post
  985. and then their relative names, which is where naming them, the correct names across
  986. the top there, becomes much simpler to manage and maintain.
  987. So if I just do this a second, it does make it a little bit easier.
  988. So that is then going to be ISBN.
  989. And then inside this one, it is going to be author.
  990. Inside this one, it is going to be publisher.
  991. Inside this next one, it is going to be description.
  992. Inside this one is going to be rating.
  993. Inside jacket image, we are going to use ISBN again.
  994. And that will all make sense in a second.
  995. And inside available copies will be the available copies.
  996. So that's going to post those elements and put them into our database.
  997. Our jacket image does need to be copied into place, but we're going to do that
  998. separately. And then we've got all of that information there.
  999. Now, to get our jacket image and to pull that in from its
  1000. location, the first thing we need to consider is where it actually is.
  1001. If I go echo $sql for a second,
  1002. when I post to it now, I
  1003. didn't put it. I'm forever not doing that.
  1004. There we go.
  1005. Here it is.
  1006. We get this string here. So, replacing the books, let me just put that in as a new,
  1007. nothing for a second. Sorry, I don't understand.
  1008. Shut up, Siri.
  1009. No, we're off. So, let me post.
  1010. Thank you. So, as I'm saying, replacing the books, name ISBN there, the values are
  1011. coming across here.
  1012. And as I go through, we have our jacket image, which is coming here.
  1013. So, we don't actually yet know where our picture is.
  1014. No. So what we need to do is on our ad book, where we did our hidden
  1015. for our jacket image, and I said the book there, I was thinking along the right
  1016. lines, but I was slightly ahead of myself, and I hadn't quite realised that actually
  1017. we do still need to have our image set to us.
  1018. So if I save that, and I come back up to here, and this time,
  1019. all I want to do is post our image.
  1020. So I can save that. It was only image, not images.
  1021. It was jacket image, to be precise.
  1022. Save that, and put that.
  1023. Now, let's go back a page, and there we go.
  1024. That's what I expected.
  1025. one long URL which will take me directly to that picture.
  1026. And what I can do is I can use that file get content to find that
  1027. picture like we did previously.
  1028. I can say that the content for our picture
  1029. is equal to file get
  1030. file underscore get and I want underscore contents
  1031. and I want to get those contents from my post image
  1032. now once I've got that
  1033. I want to write it to a place within my folder structure so I'm going to
  1034. image equals, I want to fopen, which is going to be an
  1035. open command to create something.
  1036. I need to tell it where to store it, which in this occasion is going to be in my
  1037. image folder. So I'm going to say full stop forward slash, in speech marks,
  1038. full stop forward slash image,
  1039. forward slash jacket.
  1040. And that's where I want to contain it.
  1041. And I actually want to give it inside that jacket, the ISBN name.
  1042. So I'm gonna say dot, dollar sign, underscore post.
  1043. And I want ISBN as its name.
  1044. And use that dot to concatenate again.
  1045. And I want to store this as dot jpg.
  1046. So it's storing it in that location.
  1047. opening that comma to write information to.
  1048. Then what it's going to do is fwrite,
  1049. because I've f opened, I'm going to fwrite.
  1050. And what I want to fwrite is to my dollar sign image, my
  1051. opened image, my dollar sign content.
  1052. And then once I'm done with that, I'm going to do F close and I have to tell
  1053. it what it is I'm closing so what I should do is produce my
  1054. SQL statement get the contents from that picture I've sent it and in my
  1055. images folder with the ISBN as the name save it as a jpeg in that place
  1056. so if I save that I put that so it should work without me having to...
  1057. Let's go back. I shouldn't have to write to the database, but I should be able to go
  1058. there. It's come back here. It's got rid of that information.
  1059. And if I go onto UwAmp,
  1060. and UwAmp www.imagejacket,
  1061. written today, the 9th of September at 5.30,
  1062. picture so it's copied it directly from the internet into my documents as that jpeg
  1063. file for me all I have to do then is execute this SQL command
  1064. to make sure that it puts that book into my database correctly so I'm going to do
  1065. dollar sign connection I want to query
  1066. and the query it's going to do is dollar sign SQL
  1067. and put that in place.
  1068. And if all of that has happened, I need to go back to my, I need to
  1069. header location and I want to change that to admin.
  1070. Now, let's put that up.
  1071. Let's go back a page. There it all is.
  1072. Available copies. I'm going to say three.
  1073. Average rating. I'm going to say three.
  1074. I'm going to go add book. It's brought me back to the library.
  1075. So it's
  1076. we know the picture is in place if I refresh this do we have that additional book
  1077. no one of these days I'm gonna do something right first time okay
  1078. let's have a look and see why we don't let's go echo dollar sign
  1079. SQL and then die
  1080. bit severe but it's not behaving so let's kill it and let's go back
  1081. I'd work
  1082. there's my add command there's my replace let's go copy into my
  1083. paste and
  1084. all looks pretty good to me let's go hit that and see what it says you have an error
  1085. near there the horcrux himself to be okay
  1086. okay let's go reform my sql and you're also going to help as much as i wanted it to
  1087. the issue is in this section here.
  1088. Voldemort's.
  1089. Gotta love it when they use correct English.
  1090. Okay, we can overcome this though.
  1091. That's not the end of the world.
  1092. What we need to do is we need to set our description
  1093. to be in some way edited. So if I put it as a
  1094. json, no, json underscore encode and I
  1095. just simply json encode my description that should work I
  1096. am going to think ahead for once if I have an Irish author oh hey
  1097. oh can I have anything like that or a publishing body that has a
  1098. pluralized name that's going to give me the same error so let me put that up there
  1099. let's go onto here and back
  1100. paste and let's copy this this time
  1101. and go paste
  1102. what we should get instead old and what's it still there
  1103. nothing actually changed.
  1104. That's annoying. It could have been me.
  1105. JSON encode.
  1106. Okay, add put.
  1107. No, that didn't change. Okay, well, we'll do it the other way.
  1108. Rather than JSON encoding it, because JSON encoding clearly isn't actually being as
  1109. effective as I was hoping, we'll base
  1110. 64 end code.
  1111. And now, if I put addbook up, this will look really strange.
  1112. Addbook, and they are base64 strings.
  1113. As I hope this time around. Copy, and let's go paste,
  1114. and that's all in there.
  1115. hmm no I'm not happy with that solution to be honest with you that's not the
  1116. cleanest way of dealing with that option real escape string
  1117. that will work I can put that in place rating field is
  1118. not happy with I probably called it something wrong r8
  1119. ratting there
  1120. that's not going to give us our answer though that's not going to put it in place
  1121. I've done rating the save that now that will go through and that will insert
  1122. correctly and that would give us that extra buck I'm just not overly keen
  1123. there but that being said I can get rid of that element there I can get rid of that
  1124. element there bring that back save that and upload that and that would allow me to
  1125. add a book that would go into my library and I can come back then straight to my
  1126. admin page.
  1127. Add book and go back to my
  1128. admin page. Find another book um
  1129. Lord of the Rings
  1130. Fellowship of the Rings to Towers add book, it brings it through add book
  1131. and in my database
  1132. it's not giving me the additional Lord of the Rings book but I bet you in Yuan
  1133. no that's Heidi, Yuan I get an additional jacket image
  1134. okay Why is it not liking that?
  1135. Echo, $SQL.
  1136. fairly certain I don't usually do a die in that sort of way but I'm pretty sure it
  1137. works
  1138. So why isn't this one happy then?
  1139. The fellowship of the ring
  1140. to another king
  1141. Paste.
  1142. An uncopper.
  1143. Ah, incorrect integer value for available copies.
  1144. Okay, we can't say that they don't have an available copy of that book.
  1145. In the way that our database is set up, available copies has to have a number.
  1146. So we can get around that as being an issue by saying available copies is
  1147. required. it.
  1148. Now when I put that up there and I refresh this page here,
  1149. if I try to submit it, it says please fill in this value first.
  1150. So if I fill in that value, we then get the correct value.
  1151. And if I was to get rid of my die command
  1152. and do that,
  1153. I come here and in there we
  1154. get
  1155. Perfect. All working, all submitting, all saving.
  1156. I'm going to stop the video there.
  1157. I'm going to have a quick think and look at how I could do the encoding in a
  1158. different way. I'm not happy with the base 64 of it.
  1159. I want it in a nicer, cleaner way, where if we were looking into our database, we
  1160. could see the authors to see where the similarities in the authors are and that sort
  1161. of thing. I will jump back on in about five minutes when I've had a little bit of
  1162. play and figured something out.
  1163. okay so literally seconds worth of um looking and i've realized
  1164. what to do or learned what to do i should say rather than base64 encoding or
  1165. javascript encoding what we can actually do is tell mysqli through our connection
  1166. to encode it for us so i can say dollar sign connection
  1167. and what I want it to do is real underscore escape underscore
  1168. string. And what that's going to do is it's going to take any commands, anything so
  1169. far we've given it and remove any unwanted characters.
  1170. So I've already had a test and you can see it's worked on those two there, but let's
  1171. go in and let's have another look at something else.
  1172. So Bob, Airverse,
  1173. WeAreLegion. are legion
  1174. we are legion we are bob denisee taylor there we go
  1175. got these elements in place here signed edition is all three books on amazon and i'm
  1176. just going to put in bob reverse there so you can see that let's check in 43 copies
  1177. add book and in my database then refresh that you'll see that
  1178. We are legion, we are Bob is there, Bob-a-verse is there with the little symbol in
  1179. place already there. So if I scroll all the way back, you can see it's been escaped
  1180. and they've included it there.
  1181. Just to do another demonstration,
  1182. let's see,
  1183. ready player one, and it's got a comma in its
  1184. description already. let's add in four books and if I refresh
  1185. this we've got ready player one and the comma is already there it's able to handle
  1186. all of those elements directly and as expected my book pictures are all starting to
  1187. appear in a much better way as well there's a large icon so you can see the Martian
  1188. you can see the original books Lord of the Rings the Harry Potter book and the ready
  1189. player one and we are Legion books already, all of those pictures being directly
  1190. downloaded so that we can use those within our system.
  1191. Thank you very much for watching again.
  1192. I know this one has been a very difficult video, a very difficult video for me to
  1193. record as well, going back and forth and all these different pieces.
  1194. If you had noticed the timing, you probably won't because I generally put myself
  1195. over the clock. I did start this around about 11 o'clock this morning and it is
  1196. currently quarter to six. It has been a very long slog.
  1197. Do let me know if it's too confusing.
  1198. I'll try my best to break it down into smaller sections.
  1199. I will re-go back over and re-record elements.
  1200. I want you to understand this.
  1201. I understand that you have to deliver this to your students.
  1202. It's not me sat in front of them.
  1203. They're not watching these videos.
  1204. You have to be able to confidently show them what you are doing.
  1205. So if you need any more instructions, any more guidance on it, then please do reach
  1206. out and contact me.
  1207. Thank you very much. Hopefully you have a nice two weeks.
  1208. There's not very long left in school here now.
  1209. Hopefully it'll all be done soon.
  1210. Thank you.