Retrieving data from MySQL using PHP

Form for user’s input Login action page: Connection with database Retrieve user’s input Select a record from user’s table with same email and password Count the number of row in result If one row is selected then fetch its values and store in session variable, otherwise send an error message on main page

pptx28 trang | Chia sẻ: dntpro1256 | Lượt xem: 730 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Retrieving data from MySQL using PHP, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.1Summary of the previous lectureFILES super global variableFile uploading in PHPStoring reference of uploaded file in databaseCONNECTIONS: user registration with file uploadBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.2Outline Retrieving data from MySQL using PHPCONNECTIONS: login functionalityBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.31. Retrieving data from MySQL using PHPConnection with databaseExecute Select SQL commandMake display structureWrite data Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.41.1 Connection with databaseBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.51.2 Selecting dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.6SELECT command in SQL:SELECT column-nameFROM table-nameSELECT user_NameFROM usersSELECT *FROM users1.2 Selecting dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.7Condition selection:SELECT column-nameFROM table-nameWHERE conditionSELECT *FROM usersWHERE user_Id>41.2 Selecting dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.81.2 Selecting dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.9Counting rows:mysql_num_rows(variable);1.3 Display structureBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.10 User Name User Email User Password User Picture        1.4 Writing dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.11mysql_fetch_array(result-resource);mysql_fetch_array($result);1.4 Writing dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.12$result=$row = mysql_fetch_array($result);1Aliali@yahoo.com123upload/123ali.jpg2Umarumar@yahoo.com123upload/123umar.jpg$row=1Aliali@yahoo.com123upload/123ali.jpguser_Iduser_Nameuser_Emailuser_Passworduser_Picture04123echo $row [1]; echo $row[‘user_Name’];1.4 Writing dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.13 User Name User Email User Password User Picture ”> User NameUser EmailUser PasswordUser PictureAliali@yahoo.com1231.4 Writing dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.14Heading Row ”> User NameUser EmailUser PasswordUser PictureAliali@yahoo.com123Umarumar@yahoo.com1231.5 ExampleBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.15Starts a HTML pageConnection to databaseSelect commandQuery executedCounting number of rows1.5 ExampleBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.16Heading rowLoop startsKeeps row 1.5 ExampleBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.17Displays nameDisplays emailDisplays passwordDisplays imageSets sourceEnds loopEnds table1.5 ExampleBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.18Records in user’s tableOutput from the table2. CONNECTIONS: User login Form for user’s inputLogin action page:Connection with databaseRetrieve user’s inputSelect a record from user’s table with same email and passwordCount the number of row in resultIf one row is selected then fetch its values and store in session variable, otherwise send an error message on main pageBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.192.1 CONNECTIONS: User login formBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.20emailPasswordPost method2.2 CONNECTIONS: database connectionBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.212.3 CONNECTIONS: Retrieve user’s inputBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.222.4 CONNECTIONS: Select recordBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.232.5 CONNECTIONS: RedirectBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.24No. of rows selectedFetch user informationRegister session variablesredirectIf user’s input is invalid2.6 CONNECTIONS: user pageBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.25User profileUser’s picUser’s informationactions2.6 CONNECTIONS: user pageBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.26Profile divImage divUser’s info‘picture’SummaryRetrieving data from MySQL using PHPCONNECTIONS: login pageBasharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.27References Chapter 30, “Beginning PHP and MySQL” by W. Jason Gilmore, Apress publisher, 4th edition; 2010, ISBN-13 (electronic): 978-1-4302-3115-8.Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.28

Các file đính kèm theo tài liệu này:

  • pptxlec30_retrieving_data_from_database_0625_2026978.pptx
Tài liệu liên quan