Class Checkpoint

Making Parkwood Vale · Part 10 of 13

Part 9

Build the profile page: show and update the user's details and upload a profile picture.

We add the update part of CRUD (create, read, update, delete). Signed in users can see and change their own details and upload a profile picture. In this part: 0:00 CRUD, and what the profile page needs 2:36 Selecting the signed in user's details 7:00 Checking the result and reading it into variables 12:07 The profile page layout with Bootstrap 15:00 A form filled in from the database 19:11 Showing loan tokens without letting users edit them 31:02 Sending the form to update_account.php 34:33 Showing the profile picture, or a default if there isn't one 39:05 Adding a file upload to the form 40:25 Saving the changes with an UPDATE query 54:42 Saving the uploaded picture Software: Adobe Dreamweaver, UwAmp, HeidiSQL, PHP, MySQL, Bootstrap.
Transcript
  1. Okay, so second video for today then and in this video we're going to be looking at
  2. some CRUD functionality. So CRUD is a technical term given to PHP development.
  3. It stands for Create, Read, Update, Delete.
  4. And we're going to be looking at those sort of functionality around the profile side
  5. of our pages. We're getting very close to the side of completing our basic
  6. functionality within our website.
  7. We're going to look at creating our profile today and part of that is going to be
  8. uploading a file from our users documents
  9. Into the website of things so a profile image or something along those regards
  10. Okay, let's get into it
  11. Okay, so here I am back in my student account and as you can see I've already logged
  12. in Parkwood Vale as my admin account and brought up the profile page.
  13. You can see from my profile page then that unlike my copy, I have my
  14. profile image, my email address, which is a non-editable field, the heading for my
  15. profile settings, and then a form that will allow me to edit and put in all the
  16. information directly from my database.
  17. So what it's done here is a key element towards our CRUD system.
  18. So we've created when we created our account last session.
  19. We've read the information from our database into this section here and this will
  20. allow us to update our information as well.
  21. The only thing that's missing from that CRUD element is the delete function.
  22. To get hours looking more like this then, what we need to do is edit this account
  23. page.
  24. So here I am in my Dreamweaver session.
  25. I have my account page open and I've got in place my
  26. if my session was empty it took me back to my login page otherwise it brings me
  27. through and connects using my header header.php for my information
  28. what i'm going to do next then is
  29. query the database to get some more information out than i currently have
  30. because as you can see at the moment i've got my email address my phone name and my
  31. surname on whether or not i'm an admin whereas on the Parkwood Vale side of things
  32. we have our email address our phone name and surname the address details of our user
  33. and the profile page their profile image so we
  34. need to get some more of that information out and the way we're going to do that it
  35. is with another simple MySQL query after that include section
  36. here so I include header does include that require section to get my connection in
  37. place so I can dive straight into doing my SQL.
  38. My SQL in this case then is going to be again a select statement but this time I
  39. want to select everything from my table missing out the password side
  40. of things so we don't want to show the password at any point.
  41. So I'm going to bring back email, I want forename, I want surname,
  42. I also want the address details let's just double check what
  43. I've called it in my database by going into Heidi and opening
  44. up my database connection in my users detail then in my
  45. users table I've called it street town and postcode so let's put that in place then
  46. so I want street town and postcode
  47. from that section there I also want to know whether
  48. and i've included these loan tokens so we're going to show those as well so i'm
  49. going to say is admin and did i just call it and it is
  50. loan tokens
  51. now that's what i want to select i need to tell it where it can find that so from
  52. and let's capitalize that nice and clear and i'm going to say users because that is
  53. the table that's storing that information just again in here it is my users table
  54. and we need to put a query in place so i say where that should be a capital where
  55. and i'm going to say email is equal to
  56. and again i'm wrapping these single quotes in place and i'm going to
  57. concatenate inside of there my session details this time around because we're not
  58. posting anything to this so i need to grab it my session.
  59. In my session, I'm going to use the email function there to bring that back.
  60. Now, if I was to save that in place and put that for my account
  61. page, so I've got to remember I've put the right one up, put that up in place there
  62. and just simply refresh this page then, nothing has happened.
  63. Nothing has changed because I wanted to print MySQL as well.
  64. R and just put in my SQL statement
  65. and then save that and put that in place.
  66. Now, when I refresh it this time, I do get that SQL statement.
  67. It's up here out of where my other elements are because in Dreamweaver, my
  68. other print was done here. But that does give me exactly what my query should be.
  69. And if I take that query into the query section over here, and I run that query
  70. and it tells me I've missed both street somewhere let's
  71. see
  72. street name that's why okay so let's go back into here then it's not a street it's
  73. street name and that shows that importance of having the same
  74. element in both sections and email didn't pull through the
  75. email and I can run that and
  76. with Heidi because it allows me to pull back and check my SQL as I'm going along.
  77. So now I can take that. I know it works.
  78. It's brought my one user there.
  79. I can take it back into here and just replace that section.
  80. So all of that set up, I've got my SQL.
  81. I don't really want to print it there.
  82. That's just so I can check how it was running.
  83. What I want to do instead is do my connection,
  84. dollar sign then and i'm going to say result for where to store the result of my
  85. query
  86. equals and i'm going to say simply connection
  87. run query and my query is my sql
  88. just like we used when we were writing our sign in function
  89. so it's the same sort of principle and just like with our sign in function I want to
  90. check to make sure that it's brought back a result I'm going to say if dollar sign
  91. result
  92. and I'm going to say num rows like I did on our login I say doesn't
  93. equal one
  94. then I want it to take us back to our header page so if it's done a query if it's
  95. tried to do it if
  96. information and it's found more than one record more than one row something has gone
  97. wrong in my database send me back to my login page otherwise so you can say down
  98. here else and then I'm gonna loop through to populate the different variables
  99. as I want to use them to design my form so I'm gonna say while
  100. and I'm gonna put in my while loop I've capitalized the W there that's why it's
  101. knock on blue. I'm going to say while dollar sign row
  102. equals result.
  103. And I want to, in this case, fetch the
  104. associated files.
  105. So it gets the association names as well.
  106. So I can easily reference them.
  107. Then I'm going to loop through here and create variables for these different
  108. elements to make it easier for me to display them so what I'm going to do is paste
  109. them there and simply give them all their own line and their own space
  110. now how you decide to do this is completely up to you there is no easy simple way to
  111. do it it is a little bit of manual editing what is admin
  112. and put that in place there on some IDEs and actually on this one it's even
  113. allowing
  114. use the control key bottom left hand corner of my keyboard what I can do is I can
  115. target and do several things all at once.
  116. So I've gone and I put a dollar sign in at the start of all of those to create them
  117. all as variables press the end key on my keyboard and then I'm going to say equals
  118. and they're all going to start with dollar sign row because they're referencing our
  119. row array created up here.
  120. Now the values inside these are all going to be relevant to the values we've called
  121. here. So let's see if we can use a small cheat again.
  122. I'm using the control key. I'm going to copy all of those and control key to
  123. click into all of these elements and paste and that didn't allow it to work.
  124. No mind. Sometimes you win some, sometimes you lose.
  125. Let's just manually copy these over there.
  126. Now I'm putting these in place and I already know I've made a slight mistake.
  127. I'm going to go back and rectify that in a second and that is simply that I need to
  128. wrap all of these in a single quotation so that it knows that they are the
  129. values. If I double click to highlight them then put it in single quotation and it
  130. will pick up quite nicely and put that in place for me.
  131. Make sure you press the right key.
  132. Now as I've done all of this all I'm doing is taking that information from my
  133. database and I'm checking if there's only one of them and then storing the values
  134. it's given me in separate variables so that I can pre-populate these different
  135. sections with that variable information.
  136. Now if I save this page put this page back up and refresh this
  137. page what I get is a couple of different errors it's not quite happy with line 11 or
  138. line 13 see what's on line 11 then if results num row doesn't equal one
  139. and undo that there
  140. result does help if i spell it the same and then it said line 13 that shouldn't give
  141. me an error now let's put that up and just put this refresh this no errors
  142. perfect exactly as i'd expect it to be.
  143. I am going to go back over here in Dreamweaver.
  144. I'm going to scroll down and I'm going to go to my print section by here where I'm
  145. printing my session data. I no longer want to print my session data.
  146. I'm going to get rid of that section there.
  147. I'm just going to show you that if I now echo dollar sign email and I'm going to say
  148. as one section there, I'm going to copy that line paste it a couple of times
  149. echo for name and echo surname save that
  150. and put that up when I now refresh this I get that information
  151. from my variables directly from my database so I'm pulling that
  152. information through using that CRUD functionality using that retrieve that second
  153. section of the CRUD element to pull the information from my database.
  154. Now I have that in place I just need to design and I've actually forgotten one there
  155. actually let me see if it's in my database see if I haven't forgotten it there as
  156. well. I have perhaps I can do this a different way though.
  157. What I'm going to do here then is I'm going to put my profile picture my profile
  158. page together.
  159. I have my background in place my section there to start with and then I'm going to
  160. go in and put in a
  161. now I'm gonna put in a div for my class equals and
  162. in speech marks and I'm gonna say container and it's gonna be a rounded
  163. container and I'm gonna say that the background is simply gonna be white
  164. and that there's gonna be a margin on the bottom of this to space it out which is a
  165. margin of five and everything I'm doing with my form there is going to be inside
  166. of this section here.
  167. I'm then going to split this into two sections because I want a row.
  168. So div class row to be able to
  169. have my different sections.
  170. Taking up one third of my page.
  171. So div class, I'm going to say simply, uh, to
  172. start with at least call
  173. three, taking up a third of my page is going to be my profile picture.
  174. Taking up the other remaining four thirds of my page, because remember it's all
  175. split by 12, are going to be my details.
  176. And if I save that and I put that up for a second,
  177. nothing's changed. I haven't actually given it anything to display, so I'm not
  178. surprised that nothing there has changed.
  179. I'm going to ignore
  180. focus on this side because this is the easiest side to set up and we have our
  181. profile setting as our title.
  182. So over on this side here then I'm going to put in my heading section and this is
  183. just simply on my setup as a H4 and I'm going to put in profile
  184. and settings.
  185. Now with that in place underneath that section there I'm going to create my form
  186. and my form action is going
  187. to be in place for a second I'm just going to hold that the method is going to be a
  188. post method and I'm gonna give my
  189. form an ID of account
  190. form. Now there's my form in place.
  191. I'm going to start putting in elements within that form of how I want to display
  192. different sections. But if I come back here a second and have a quick look, you can
  193. see that this is in a row of six by six and these are in rows of 12 so that they can
  194. take the full space. So let's check in a div class and it's going to be a row
  195. here. I don't need a set container for it and in this section I'm gonna have div
  196. class call MD6 to give it
  197. half of my space and I'm gonna have a call MD6 as well because that's my first and
  198. up for and surname first and last name elements so let's give those some space
  199. now inside there then I am gonna set up my
  200. label for my in my input boxes.
  201. I'm going to put my label in first this time around so my label appears above it.
  202. The class is simply going to be called labels.
  203. And my label here is going to say first name.
  204. I'm going to do the same process underneath for last name.
  205. And then I'm going to have my input boxes.
  206. So input and the input
  207. as it is just a text type it will be just text it's not password it's
  208. nothing fancy or anything like that and it is going to take a form hyphen
  209. control for its styling now i need
  210. to give it a name the name everywhere else has been for name
  211. so i'm going to stick with for name
  212. and that's going to have my section in place.
  213. If I copy that down here and I put it in place for surname
  214. and that should be the only change I need to make at the moment.
  215. When I push that up and refresh my page,
  216. I now get my elements in place.
  217. But that's far too close to the top of my page there.
  218. I don't have the same sort of spacing that I did there.
  219. is go back to my container after my background color here and I'm
  220. going to put in a div class
  221. equals p-4 and what that is going to create for me and I need to put it at the
  222. bottom of this one as well is a padding of four wrapping around the whole process
  223. so if I do that that should push back to there
  224. and let's just sort out this indentation as well so it's all nice and neat
  225. put that up and let's refresh it and we now have that bit of spacing
  226. it's not perfect inside here yet we are still working we haven't got our margin
  227. there but we have got our spacer on the top
  228. we have our four name set up here with our input boxes for first name and last names
  229. I'm gonna do the same thing here now I'm gonna take another row I'm gonna drop it
  230. below but instead of having call of sixes I'm gonna have calls of 12
  231. and in those 12 sections then I'm gonna have my address details over here I've
  232. called it address line 1 2 and postcode on my database here I've called it street
  233. name town and postcode so for this version I will change this to say street name
  234. and And actually, I can just change that one there.
  235. I'm going to say this is town.
  236. And I need one more of these 12 combinations here for postcode.
  237. And I can save that. When I refresh this page, after
  238. putting that page up,
  239. that will allow me to have these elements in place.
  240. now i did have that section on my database brought back as to whether they're an
  241. admin i also had the tokens in place on Parkwood Vale there's nothing there for
  242. it but if i actually go into the admin section manage users and then find that user
  243. on the manage user edit section i did include a toggle for
  244. whether they're admin or not so i'm going to check that into well i'm
  245. section here because we don't want an individual user to be able to change whether
  246. they're an admin or not. But we do want to display to them what the current token
  247. usage is. So I'm just going to take one of these elements here.
  248. I'm going to put in underneath tokens.
  249. Tokens here. It is going to be a type of text there.
  250. And as well as having all of these, what I'm actually going to do is put it
  251. as disabled.
  252. Now that, if I put that up, should show you over here
  253. tokens that I can't actually interact with or edit.
  254. I can go into these ones, but I can't go into this one.
  255. That's because it's been disabled to the user i am going to replicate this and
  256. change the input type to hidden
  257. for my tokens the input here is going to be tokens and tokens
  258. and i just need to go through and update these so post code i want town
  259. and notice how it's all lowercase and i'm going to call it street
  260. name caramel taste so they're all in place
  261. now that's there the hidden element is what will actually post for
  262. me so I don't want that one to be disabled that allows me to have it in place
  263. and not necessarily show the user how it's editable all of that's
  264. there and it's given me the look of my form my The phone's not quite laid out as
  265. nicely as I like it. So I'm going to scroll back up to this row here.
  266. And on my row, I'm going to add in a padding again.
  267. And I'm going to put in this type of padding of two.
  268. Put that up.
  269. Refresh it.
  270. And there we go. We've got a little bit of spacing around it.
  271. I'm quite happy with a smaller amount of spacing.
  272. I think I give too much on that one.
  273. I'm happy with a smaller setup.
  274. them. The main difference here then is I'm not pre-populating these fields
  275. and I want to pre-populate them.
  276. So the way that I do that is I come along to my input here and I
  277. give my input a value. So I can say value
  278. equals and then in speech marks I
  279. can actually put in a PHP tag and echo out so use the
  280. echo command my variable for forname
  281. and i'm going to take that same line i'm going to copy it to my last name here
  282. and change it from forname to surname i'm going to do the same here so that's the
  283. street name value is street name and
  284. Dreamweaver will try and help you giving you the names of your variables to make it a
  285. little bit easier for you over here then i want this to be town i want this to be
  286. space there and then postcode and over here
  287. i'm going to do the same thing for my disabled value of tokens
  288. or loan tokens as I called them earlier
  289. and I also want to put that let's make sure I grab the whole thing
  290. in my hidden value as well so now when I put that up
  291. and I refresh my page I get my details filled in as you can
  292. see street town and postcode are empty because in my database, street, town, and
  293. postcode are empty. I want to be able to type in what my street is, fill in my town,
  294. my postcode, and hit save on my update save changes button so that it writes
  295. it to my database.
  296. Back in Dreamweaver then, the last part within my form.
  297. It does need to go actually outside of all of these elements here.
  298. Let me just zoom out a second so I can trace this back.
  299. there we have that you'll just have to go to the bottom here then that's not a
  300. problem I'm gonna add in class
  301. label okay let me indent my labels a second to
  302. make sure everything is nice and tidy and
  303. there I have my nine nine I'm gonna take another row then
  304. so down the bottom here that's my nine is that my nine
  305. yes and that's the
  306. let's move my form above that
  307. just so that's there
  308. p there form is there
  309. form needs to go after that one let's get my layout clear in my head there we go
  310. so now what i can actually do down here is put in a div
  311. class and the classes then go into b of
  312. row
  313. and I'm going to do the same thing as a div
  314. class equals call
  315. md 12 and in there
  316. my input
  317. type is going to be submit and
  318. that should be it if i put that up
  319. refresh it my submits there now it's messed things up ever so slightly so let's try
  320. and get this formatting back and get everything right to where i want it to be
  321. so minimize that using that arrow there nice and simple so let's see then where we
  322. to
  323. labels there, there.
  324. do a row there
  325. my form is there
  326. okay could possibly be because i have nothing in here yet so let's just chuck
  327. something in here and h2 uh profile image
  328. just to get started and put that in place and put that up
  329. profile image is there okay
  330. md
  331. Ah, I know I done
  332. Maybe
  333. So that is in my row
  334. That's in my row. That's my column of three, my column of eight.
  335. And then I have a separate row there.
  336. So that's column of eight.
  337. Let's just get it back to the way it was for a second and reset that button.
  338. put that up refresh it and it's back over there okay perfect so that's
  339. where I want it
  340. and let's trace this through then so div column nine is fine that's
  341. fine
  342. I just want to move my form to be there.
  343. Save it, put it up and let's see if it's
  344. moved it over there.
  345. Let's leave the form there then.
  346. And then down here.
  347. put that up
  348. right that's that that's fine
  349. it's that row there that's fine below underneath that's the row for my
  350. first name and surname as it should be that's that section there
  351. let's take my form outside of that section
  352. let's take my form here outside of that
  353. section save it and put that up
  354. nope second move that form it doesn't like it you leave it there for a second And
  355. CY.
  356. Let's go inspect.
  357. Container.
  358. Okay, so there's my form.
  359. my call md3 is not being picked up because i don't think it's got any content
  360. so we will leave it as it is and we'll come back to it and see if it works and
  361. shifts over when i want it to so that's all in place where i want it to be right now
  362. let's re-enable these elements or really expand these put another row
  363. in div class row.
  364. I want a div class.
  365. I'm going to call this one call
  366. MD 12.
  367. So it fills up the whole page.
  368. And then inside this one is where my input type
  369. submit will go and I can say no
  370. I
  371. did this button on there and I'm just gonna leave it like that for a second and put
  372. that up so I have my submit button I do need to
  373. bring this down ever so often so I'm gonna say P
  374. one
  375. and refresh that so let's brought that down a little bit like click submit nothing
  376. happens because I haven't told it where to post it or anything like that I need to
  377. give it a page to go to in my form and let's re-expand that form
  378. action is going to be my main page and I'm going to say update account
  379. and save that. Now when I push that and
  380. refresh continue now if I submit this it tries to go to update account that
  381. doesn't exist exactly as I expect it to be.
  382. I don't want to resubmit the form and let's just get back into my site.
  383. So I can now put these details in place and I can have it post that information into
  384. my form. The only thing that's missing, the only thing I haven't included yet is my
  385. profile picture section. Now in my profile picture section, I did want to put in
  386. place my email address. So I can just simply here, put in my PHP tag,
  387. echo out dollar sign email so that the user can see
  388. link to this account and if i refresh that then
  389. it's not showing me anything because i forgot to press the put button if i refresh
  390. this i get my email account at the top here
  391. i didn't want it at the top i want it next to it so let's have a look and see what's
  392. going on with my inspect now we have some content in there and i've got my p row
  393. there my form there as expected
  394. calls calls tell you what i'm missing a row inside my form
  395. i need to tell it to put a div class row in place
  396. and then all of this information so that there that there
  397. needs to be tabbed over so that they fall
  398. inside my row here which is the row that
  399. belongs to my form.
  400. Save that, put that up and let's refresh it.
  401. And then we have it. It's jumped back to the right place, right where I expected it
  402. to be.
  403. Just missing that one section.
  404. Now I'm going to put in place inside my MD3 section here, my
  405. profile picture for where their profile should be displayed.
  406. I'm going to put it above that section and it's simply going to be an image and its
  407. source is going to be a source that is relevant to where my current section is.
  408. I'm going to go into my images folder and I have a profile pics folder and I have a
  409. base profile pic to start with.
  410. I'm going to say here, so source is equal to, and
  411. let's just use the browser to make it easier, images, I want profile
  412. pics and then I'm going to attach something to the end of it.
  413. In this section then, I'm going to include some PHP to echo
  414. the user's email.
  415. And I wanted it to be the dollar sign email.
  416. So let's get rid of all those help guides.
  417. It does help, but not when it's in the way.
  418. And I want to end it with .png.
  419. So if I save that and find my account page, put that
  420. up and refresh it,
  421. a nice lovely warning telling me that I don't have a profile picture.
  422. That's perfectly fine. We haven't set one yet.
  423. We need to put that in place. But what I can actually do is check to see if my email
  424. picture exists. And if not, instead, I want to put in place
  425. my base profile image. So what I'm going to do here is include a piece of PHP.
  426. I'm going to say if, and this is where I want to check if the file actually
  427. exists.
  428. So I'm going to use the php file exists command.
  429. So I'm going to go into my browser.
  430. I'm going to check because it's always good to reference back.
  431. php file exists to check if my file exists.
  432. and I want to see quite simply file exists.
  433. So I'm going to say in here if file underscore exists
  434. and the file I want to check if it exists is my PNG
  435. for my picture. If my file exists, then
  436. I want to go down to my next line.
  437. Otherwise, I want to display something different.
  438. So I'm going to break out of PHP here.
  439. I've got my file exists. If my file does exist, so I know it's there, I'm going to
  440. use the image command for my picture and put that in place there.
  441. I need to come back into PHP,
  442. finish off my bracket, my curly bracket for my if,
  443. and I'm going to say else. So if that file doesn't exist, that's when I wanted to do
  444. this section here and again and the PHP but I want to break out of PHP
  445. here and restart PHP on this side
  446. so if it doesn't exist my picture
  447. is going to be in my pictures folder and it is going to be the
  448. base dot jpg if i save that
  449. and put that up i should now be able to refresh
  450. and have my base picture
  451. slightly oversized so i need to go down to here on the image tag set that width
  452. equal to i'm going to say 50 i'm going to do the same thing on
  453. the actual picture that they could possibly use as well so that both of my pictures
  454. or all of my pictures aren't massively proportioned to the rest of
  455. my page.
  456. Now if I put that up and refresh the page you'll see how that is
  457. laid out. It doesn't quite reflect this directly at the moment but it's extremely
  458. close to it.
  459. There's my form set up with my submit button.
  460. I'm going to change the value of my submit button to changes and change the styling
  461. on it ever so slightly as well so over here i'm going to have a look i'm going to
  462. put in place my different style elements and what i want is for my button to be a
  463. class of btn and it is going to be a btn primary
  464. so it's a button primary and i'm going to say that its
  465. value should be and it's simply save profile
  466. now I save that and I
  467. put that up I refresh my page and now it says save profile and
  468. it looks a lot more appealing so I got my section set up here and I've got my save
  469. so when I go into the it pushes through to this section there is one last thing we
  470. need in relation to our picture uploading element.
  471. And the way that we're going to do that is our form itself is going to be
  472. a type of multipart form.
  473. And what that means is that our form will allow us to
  474. upload multi-part elements. So I want a HTML multi
  475. -part form.
  476. and our multi-part form then is
  477. not the page I wanted let's see w3 schools that's the one I wanted
  478. our multi-part form should allow us to
  479. not multi-staff I want to upload file upload
  480. perhaps I don't need for multi-part anymore
  481. So that's in place then and there's our form created.
  482. Ready for our PHP side of things.
  483. What I'm going to do there is take a short break and I'll come back to you in two
  484. seconds time with the next step where we update our profile element.
  485. Okay, so part two, what we're going to do in this section is take the data that
  486. we've taken from our database here, process it and update our table with it.
  487. So I've said that in my form, it's going to go to update account.
  488. Update account doesn't exist. And if I try and fill it in and submit it, update
  489. account gives me an error. I need to create that file,
  490. update account.php. Again, we are working with PHP files and I'm
  491. going to open up my update account.
  492. First thing, get rid of all of those elements.
  493. Second thing, jump into sign in and let's keep some of these elements we've done
  494. previously.
  495. Now we are going to include our connection.
  496. We should also still include our elements of our array management to make sure that
  497. we are putting in our error detection.
  498. I'm not going to go through that each time with you.
  499. I'm going to leave you to put that in place.
  500. I'm going to jump straight into the SQL and updating our connection and redirecting
  501. us back to the right place. If I go through and put the error detection in on every
  502. single session with you,
  503. of it too it's going to take up so much time just put in our error detection make
  504. sure you're checking for empty elements put them in errors and catching the errors
  505. and send them back if there are errors on that page so in here then I've included my
  506. connection I would do my error testing so ensure you include
  507. error testing just as a reminder and I'm going to put
  508. in place my dollar sign SQL command.
  509. My SQL command is going to be an update command.
  510. It's going to update the users table.
  511. It's going to set different properties.
  512. Now I'm going to say that set and I this is where it's going to be important to be
  513. able to concatenate things to make it easier to understand.
  514. I'm going to say set for name equals
  515. and I want a single quotes and inside here
  516. I want to grab my post information so dollar sign and it's got post
  517. and I want to check to see what the for name they've entered is now
  518. it might be that they haven't changed the value in for name but we still
  519. need to make sure we're grabbing everything we
  520. going to do the same with surname i'm going to do the same with the same thing then
  521. with street name town and postcode so street name town and postcode
  522. and i want to set well token loan tokens we don't
  523. actually need to update that but i'm going to put it in place anyway so surname
  524. equals
  525. sorry street name and actually I will put postcode here
  526. just to show that they don't have to be in order and town and
  527. I'm gonna say loan tokens and again
  528. these are all based off of the values that they should have been given to us as so
  529. I should be able to put this in place the only one that has any difference because I
  530. don't think there was a capital seam postcode now I've got that in place I'm going
  531. to terminate that and that's my element my update command set for name equals that
  532. the only thing I do need to include is after each of these I'm not going to
  533. show I'm gonna check that actually whether I need to have a comma between them or
  534. not I'm gonna echo out from here then dollar sign SQL just to see what we're getting
  535. and let's go on to count
  536. put that up on here then James Jones I'm gonna say streets I can say one two
  537. three fake street because I'm original like that town my town and
  538. postcode CF 55 6th save profile and it's brought me
  539. here it's giving me some bits and pieces it's also giving me an error on line 15
  540. line 15 loan tokens then equals did to does it tell
  541. me more about my error update users set for name surname
  542. one two three there we go town loan tokens there okay loan tokens
  543. didn't come through with anything from there we'll have a look at that in a second I
  544. do want to space these out a little bit give myself a bit more
  545. readability and account here
  546. I think I just called it I called it capital no I just called it tokens there let's
  547. keep it loan tokens and
  548. where are we to I want the account page put that up
  549. hit that back button refresh the page to make sure it's gone through and let's
  550. go one two three fake street my town there we go thank you very much for the
  551. autofill still not happy with that there but it has hasn't given me the spaced out
  552. either see account settings save that let's put that and
  553. refresh yes put that in place okay getting somewhere and then
  554. identified index loan tokens if i remember rightly i've just done that as
  555. capital L for loan tokens there should be
  556. loan tokens not tokes we're not
  557. abbreviating go like that continue there we go loan tokens but loan tokens
  558. wasn't sent and now click
  559. in the input type hidden the name is
  560. tokens
  561. So that still would have caught me a cropper.
  562. Let's check that up there.
  563. Refresh this page a few times and send that bad boy through.
  564. Perfect. Right. I'm going to take this, copy it into here.
  565. I'm going to paste it and straight away it's going to shout at me if it's wrong.
  566. And say, oh, yes, that's a very valid point.
  567. I'm trying to run an update here without telling it which row to update.
  568. So if I actually executed that and there wasn't any issues here in my settings It
  569. would apply the same details for everyone in my database.
  570. I need to put a where in place email
  571. This time running is a simply email equals CPD at mr.
  572. Jay Jones dot code at UK and Now I can run that and see if it shouts at me It does
  573. show to me it does want a comma after each of these values I believe.
  574. Chuck it in, see what happens.
  575. Now run it.
  576. Postcode, dated too long for postcode.
  577. It shouldn't have the space.
  578. Happy days. That's gone through by refresh here.
  579. It's updated these. Let's check them back to null load just so we can see them
  580. working from our PHP side of things.
  581. So over here, what I'm gonna do is go
  582. to first of all include that semicolon no comma comma
  583. comma comma comma comma
  584. postcode then as you saw two seconds ago we had that empty space
  585. within our postcode that it didn't like it doesn't like this space here
  586. so I'm gonna look check I reckon there's a trim function PHP remove
  587. spaces and if I trim PHP there
  588. move trim method it's just simply the trim method that's
  589. getting rid of a space at the end of it I don't want to do a space in the middle of
  590. it I want to do a spin to get rid of all the spaces so it wouldn't necessarily be
  591. trim I want to say PHP remove spaces from string and I can use
  592. the string replace function so over on here then what I'm gonna do is say I want a
  593. string underscore replace and what I'm gonna do is just check it
  594. it's what I'm looking for what I want to replace it with and where I could possibly
  595. find it three parameters in my string replace function first one what I'm looking
  596. for a space Now, just because of the size of this here, it does sort of make it a
  597. little bit more difficult. You can see if I go like that.
  598. String replace a space with nothing from my postcode.
  599. That will get rid of that space in postcode and hopefully bring it back down in
  600. size.
  601. I still have that one last error, though.
  602. And I've got this comma here. That's a reminder to me to put in a fix for that last
  603. error. I want to concatenate the last part of this then, which would be a space, and
  604. say, where.
  605. And in this instance, I'm going to say email equals
  606. and I'm going to join
  607. to it. Let me put in my semicolons and do it the proper way.
  608. Don't be lazy. Join to it dollar sign underscore session
  609. and I want it to be email. So I can update my details.
  610. I can't hijack and update somebody else's.
  611. We'll do an update for an admin side of things a little bit later on.
  612. So that's update account details.
  613. Let's put that up and jump back here.
  614. Go back a page, submit it and see what it looks like.
  615. We now have update users set, for name James, surname Jones, street 123 fake street,
  616. postcode incorrect. All these details there.
  617. notice it is now only five characters.
  618. It has trimmed out that space for me where my email is in place.
  619. Now, once I've done that, I don't necessarily need to echo it.
  620. All I need to do is my connection dot.
  621. No, sorry, not dot. I want to query and run the SQL
  622. query.
  623. and then I want to redirect them back to the header.
  624. So I'm going to use my sign-in page.
  625. I'm just going to steal my header location for account and drop that there, header
  626. location account.
  627. And what that will do is it will create my query, execute my query, and then
  628. redirect me back to my page. Now, it could be nice to have an updated account
  629. element, but realistically, we should be able to see that's happened.
  630. So if I was to load this a second, it's pulled that information in from the database
  631. and it's empty. Pre-populate it, save it, and now it's loaded it in without my space
  632. in my postcode. So I can see that it has applied it.
  633. Let's just have a quick look while I'm thinking about it.
  634. PHP upper function and str2
  635. upper. Perfect. That would be lovely.
  636. So in here, I've got my string replace.
  637. I also want to put an str to upper function in place around
  638. it, which will take all of the text then and turn it to uppercase.
  639. Was it all one word? Yes. Let's save it.
  640. Let's put it and let's submit it.
  641. And now it's capitalized it for me.
  642. So let's put that in place and I can save that information.
  643. Nice and simple I can log into my account I can update my details and I have my
  644. profile picture on show.
  645. What I'm going to do next then without going into the admin side of things I'm going
  646. to show you how to create a upload point for a picture using a multi-part form.
  647. It's going to be very similar to what we've done here I'm going to keep this details
  648. and then actually going to just use this form as part of it and up where our form
  649. action is up here I'm add in an element to make it a multi-part form
  650. and deep to deep to deep
  651. let me just double-check I want a HTML
  652. multi-part HTML image
  653. upload and
  654. w3 schools straightaway here it's got the action there simple I don't want that I
  655. want a multi-part form data.
  656. And it was the enc type, the encryption type was what I wanted.
  657. So I'm going to drop in alongside this, the encryption type from multi-part form
  658. data. And if I upload my account then back to here,
  659. it will not impact the way this works at all at the moment.
  660. If I add in some elements, it's all exactly the same.
  661. I can remove that element and it still works the same.
  662. My form doesn't get impacted. But what I want to do instead now
  663. is jump back into Dreamweaver and where my file
  664. is, I want to put an upload point for a file.
  665. so I got my email address I'm gonna put in input my type is
  666. simply gonna be a file its name is going to be
  667. profile image
  668. and I'm gonna leave it like that now if I
  669. up that element and refresh this page now I can choose a file I can choose any
  670. file I like and it tells me the name of the file there.
  671. If I come back into my update account section then what I can do in the update
  672. account section is check to see if my image has been uploaded.
  673. Now there is my text in place and there is that section all from my
  674. data upload. I'm going to come down here and move my head and redirect ever so
  675. slightly and I'm going to check if is set and what I want to know if something is
  676. set is my underscore file this time around rather than being
  677. my previous post elements it's my files section and if it
  678. is I just simply want to print underscore r to start with as
  679. always to see what's currently being stored inside files
  680. I'm going to say otherwise else then redirect
  681. so if I post a picture it should fall into this cache and print out
  682. everything inside files
  683. so let's give it a go refresh it choose a picture I'm going to go for the outside
  684. picture save it and it's come back here it's not redirecting me
  685. Let's have a look at what's going on with my files and delay.
  686. I think I know what's going on with my files actually.
  687. Let's bring this back a second.
  688. Let's see if I'm right first. I don't think I put that up as I should have done.
  689. And let's refresh, choose, outside,
  690. and save. I didn't. As always, I forgot to upload it.
  691. So as you can see here then, I have a new array.
  692. The array has the name profile image and inside that profile image has the name of
  693. the file that I've been given outside dot PNG
  694. It's type. It's a type of PNG and The temporary name or temporary location
  695. for where it is. It also contains its size
  696. Now what I can do when I have this so I've got all of this information here is I can
  697. actually set my file name so I say dollar sign and let's go file name equals and
  698. set it to what I want it to be and I actually want my file name in this occasion to
  699. be my email address so I say dollar sign email and I want to
  700. concatenate onto the end of it dot png now
  701. aside from that then what I want to do is tell it to move it so I'm gonna say it's
  702. location and is going to be equal to and it is
  703. my image folder forward slash and let's expand that out so I
  704. can double check my spellings profile pics forward
  705. slash and then at the end of it there I'm gonna put in dollar sign file
  706. name so what it's gonna take it's my email address and this year and
  707. actually I don't want to always lock it to a PNG not at this stage we could possibly
  708. end up with a different type of extension we'll see with that in a second so there's
  709. my location and what I want to do
  710. is move my upload
  711. from its current location so I want to move
  712. upload and I want to say that the uploaded file I want to move is in my file section
  713. and it is called profile pic so if I come back here a
  714. second you can see here it's called profile image sorry so I want that to target the
  715. profile image and what I want to do is move and let's
  716. just double check in the
  717. template so that's a temporary location I want to move that file to its new
  718. location which is simply going to be my dollar sign location
  719. and that should place it in that
  720. location for me given that I've gone through and I'm happy with where it is
  721. and how it's set up so let's save that and
  722. update account post that up here what I'm looking to happen then
  723. is if I refresh this page let's see undefined variable on line
  724. 21 which is line 21 email ah
  725. that's why try again save
  726. upload account and now try refreshing it
  727. nothing's changed there but if I go into my USB into my UwAmp
  728. www images profile pics I get a CPD dot
  729. mr.jjones file which has a size to it which is considerably bigger than my
  730. base image I also get a plain PNG from my mistake two seconds ago.
  731. If I open that up, that becomes my outside picture.
  732. So that is there. And if I was to go back to my account page, then
  733. my account picture hasn't picked up, even
  734. though my email address is there and it is a properties.
  735. Let's double check. It is a type of PNG.
  736. What did I say my account page then I said images profile pic
  737. ah I'm checking if an echo works as
  738. nice as that would be that is a mistake and it shouldn't be there is an echo it
  739. doesn't need to have that there I want to see does the profile pic there
  740. dot dot there um file exist
  741. images my email address and profile png now that should work let's refresh that
  742. still not picking that up file exists
  743. image do I need to do that
  744. image profile
  745. fix forward slash and then
  746. whatever my users email is
  747. that should work did I put that up I probably didn't know in me
  748. refresh and And there I am. I've changed.
  749. If I go into here and I change the logo
  750. It's brought me to there and that should
  751. change
  752. What I need to do now is just come back over here a second and
  753. Remove that else so it should upload the pictures Overwrite the picture and then
  754. bring me back
  755. in here then if i go to this picture it is now that picture which is perfectly
  756. fine if i
  757. press the f5 button to refresh the page it will change so it now will change
  758. automatically uh let's go um fred why not let's grab a picture
  759. of a fred images let's go for fred weasley i'm gonna grab his picture
  760. save image as in my downloads as Fred
  761. and that saved it as a JIF file brilliant let's see how it works let's see if
  762. it handles JIF files in here Fred and save page
  763. I'm Fred Weasley no sentence you say very often
  764. and let's go update account push that there and let's just go okay so we
  765. had
  766. Harry Potter Fred. Let's go Harry Potter.
  767. Run.
  768. Stick with the Weasleys. Save image as.
  769. Run.
  770. And I'm going to jump over here.
  771. Choose a picture. Run.
  772. Upload. And my picture changes.
  773. I can now change the picture for my profile for my user as well as filling in the
  774. details. I haven't added any fanciness to it.
  775. I haven't done some of the more advanced elements.
  776. as would have done within actual Parkwood Vale's version,
  777. where I could go like that and have some more prettiness to it.
  778. But the basic details are the same.
  779. And actually, in fact, I don't think that's updated wrong there, but it does update
  780. wrong there. So the prettier elements don't necessarily always work.
  781. I have that functionality in place.
  782. I can see there, I can go to Fred.
  783. It's Fred GIF and upload it and it changes me to Fred.
  784. my name to Fred over here and save that.
  785. Now as I'm saving it, not uploading the picture, it's pretty instantaneous
  786. as to it updating and refreshing itself.
  787. It's happening so quick that I can't actually distinguish the page loading any
  788. differently. So now you should be able to do two elements or three elements within
  789. that CRUD function. Remember it's create, retrieve, update, delete.
  790. We can create something because we've already done a creator in our accounts.
  791. We can retrieve the information as we've done with our form here.
  792. We can update the information as we've done.
  793. We haven't done a delete yet, but we have done a file image upload.
  794. Just to bring that back up then, the file image code was really simple.
  795. I don't need to print files there any longer.
  796. I've got my file name. I've set it to the session email name that I want it to.
  797. I've got my location to put it in.
  798. It's moving it to there, calling it after its file name.
  799. In fact, I could probably make that a smaller piece of code again, just by simply
  800. removing the need for the file name.
  801. And I've got that there. If you really want to nitpick and go really
  802. functionality and really reduce lines it's all done in one
  803. function here move files the current file comma where i want to put
  804. it and then redirect me back to my header page if i go update account and
  805. i show you that i can show you that that still works what are we at the moment we
  806. are currently wrong i want to go back to you being fred and there it is all done
  807. in effectively one but it is quite a long line of code.
  808. So again, you have to put in the error testing.
  809. I'm not showing you individually every single time error testing.
  810. This is a lot of the same functionality that will be in place when it comes to
  811. adding books to our library.
  812. Updating users, updating books, adding books, so inserting in books the details and
  813. moving the pictures to the right place and then redirecting you back.
  814. That's the basis of our transactional website.
  815. As always, any issues, drop me a message, drop me an email, and I'll do my best to
  816. further explain, further
  817. provide details or triage from a distance.
  818. Thank you for watching.