SlideShare a Scribd company logo
PHP Day 06 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com   http://www.php.net   http://www.mysql.com
PHP – MYSQL Functions  $resource_link =  mysql_connect  ( “server_name”, “user_name”, “password”); - Open a connection to a MySQL Server. mysql_select_db  ( “data_base_name”, $resourece_link ); - Select a MySQL database mysql_query  ( $query, $resourse_link); - Send a MySQL query to execute
PHP – MYSQL Functions mysql_fetch_row  ( resource $result ); - Get a result row as an enumerated array. mysql_fetch_array  ($result, RESULT_TYPE); - Fetch a result row as an associative array, a numeric array, or both. mysql_num_rows  ( resource $result ); - Get number of rows in result.
PHP – MYSQL Functions mysql_affected_rows  (); - Get number of affected rows in previous MySQL operation. mysql_error  ( $resource_link ); - Returns the text of the error message from previous MySQL operation. mysql_close  ( $resource_link ); - Close MySQL connection.
Insert the User form field values to tbl_users Assumed the form has been submitted with action insert_user_process and method post. db_conn.php <?php $db['host'] = &quot;localhost&quot;; $db['user_name'] = &quot;root&quot;; $db['pass_word'] = &quot;&quot;; $db['name'] = &quot;php_class_db&quot;; $connection = mysql_connect ($db['host'], $db['user_name'],$db['pass_word']); if(!$connection){ die(&quot;Error connecting to the database server&quot;); } $db_name = mysql_select_db($db['name'], $connection); ?>
User Table structure
The easy STATIC insert  “ INSERT INTO tbl_user_test ( user_login, pass_word, address, email, gender, heard_from, newsletter, created_on, modified_on )  VALUES ('&quot;.$fdata['user_login'].&quot;', '&quot;.$fdata['pass_word'].&quot;', '&quot;.$fdata['address'].&quot;', '&quot;.$fdata['email'].&quot;', '&quot;.$fdata['gender'].&quot;', '&quot;.$fdata['heard_from'].&quot;', '&quot;.$fdata['newsletter'].&quot;', '&quot;.$fdata['created_on'].&quot;', '&quot;.$fdata['modified_on'].&quot;');”;
Insert user function function insert_user_to_db($fdata){ global $connection; $tbl_name =&quot;tbl_user_test&quot;; //INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); $query = &quot;INSERT into $tbl_name (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= $key.&quot;)&quot;; } else{ $query .= $key.&quot;, &quot;; } }//could have done it with array_keys($fdata); … Continued
Insert user Function $query .= &quot; VALUES (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= &quot;'$value'&quot;.&quot;);&quot;; } else{ $query .= &quot;'$value'&quot;.&quot;, &quot;; } }   $result = mysql_query($query, $connection); if (!$result) { return 0; } else { return 1; }  } Full code at: day06\insert_user_process.php
Read some users from database
Function show users Code at day06\show_users.php
Output of show users
Questions
Upgrade your Login System Create database with db desiger4 and export with use of PHPMyAdmin. Authenticate a user to the login system user select * from $tbl_name where user_login = $fdata[‘user_login’]; Then compare password if it matches login else do not login. if($row[‘pass_word’] == $fdata[‘pass_word’]){ Login } Maintain session very well.
Ad

Recommended

07 Php Mysql Update Delete
07 Php Mysql Update Delete
Geshan Manandhar
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
Razvan Raducanu, PhD
 
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Matheus Marabesi
 
16. CodeIgniter stergerea inregistrarilor
16. CodeIgniter stergerea inregistrarilor
Razvan Raducanu, PhD
 
Html To JSP
Html To JSP
PlanetB4U
 
Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018
Elliot Taylor
 
Code igniter parameter passing techniques
Code igniter parameter passing techniques
Rakhitha Ratnayake
 
Laravel the right way
Laravel the right way
Matheus Marabesi
 
Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate Uri
Abdul Malik Ikhsan
 
Sins Against Drupal 2
Sins Against Drupal 2
Aaron Crosman
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06
Aaron Crosman
 
Fw1
Fw1
priyaamal
 
System performance tuning
System performance tuning
Menandro Oba
 
Jqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
prav068
 
Clever Joomla! Templating Tips and Tricks
Clever Joomla! Templating Tips and Tricks
ThemePartner
 
WordPress as a Content Management System
WordPress as a Content Management System
Valent Mustamin
 
Working with databases
Working with databases
Krasimir Berov (Красимир Беров)
 
Documento
Documento
Emersonjbn
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session
RANK LIU
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en Truuks
ThemePartner
 
FLOW3, Extbase & Fluid cook book
FLOW3, Extbase & Fluid cook book
Bastian Waidelich
 
DB API Usage - How to write DBAL compliant code
DB API Usage - How to write DBAL compliant code
Karsten Dambekalns
 
24. CodeIgniter simple login with sessions
24. CodeIgniter simple login with sessions
Razvan Raducanu, PhD
 
Latihan form login
Latihan form login
Edy Sinaga
 
Web Scraping with PHP
Web Scraping with PHP
Matthew Turland
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
Wake Liu
 
4.3 MySQL + PHP
4.3 MySQL + PHP
Jalpesh Vasa
 
Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 

More Related Content

What's hot (20)

Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate Uri
Abdul Malik Ikhsan
 
Sins Against Drupal 2
Sins Against Drupal 2
Aaron Crosman
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06
Aaron Crosman
 
Fw1
Fw1
priyaamal
 
System performance tuning
System performance tuning
Menandro Oba
 
Jqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
prav068
 
Clever Joomla! Templating Tips and Tricks
Clever Joomla! Templating Tips and Tricks
ThemePartner
 
WordPress as a Content Management System
WordPress as a Content Management System
Valent Mustamin
 
Working with databases
Working with databases
Krasimir Berov (Красимир Беров)
 
Documento
Documento
Emersonjbn
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session
RANK LIU
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en Truuks
ThemePartner
 
FLOW3, Extbase & Fluid cook book
FLOW3, Extbase & Fluid cook book
Bastian Waidelich
 
DB API Usage - How to write DBAL compliant code
DB API Usage - How to write DBAL compliant code
Karsten Dambekalns
 
24. CodeIgniter simple login with sessions
24. CodeIgniter simple login with sessions
Razvan Raducanu, PhD
 
Latihan form login
Latihan form login
Edy Sinaga
 
Web Scraping with PHP
Web Scraping with PHP
Matthew Turland
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
Wake Liu
 
Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate Uri
Abdul Malik Ikhsan
 
Sins Against Drupal 2
Sins Against Drupal 2
Aaron Crosman
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06
Aaron Crosman
 
System performance tuning
System performance tuning
Menandro Oba
 
Jqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
prav068
 
Clever Joomla! Templating Tips and Tricks
Clever Joomla! Templating Tips and Tricks
ThemePartner
 
WordPress as a Content Management System
WordPress as a Content Management System
Valent Mustamin
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session
RANK LIU
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en Truuks
ThemePartner
 
FLOW3, Extbase & Fluid cook book
FLOW3, Extbase & Fluid cook book
Bastian Waidelich
 
DB API Usage - How to write DBAL compliant code
DB API Usage - How to write DBAL compliant code
Karsten Dambekalns
 
24. CodeIgniter simple login with sessions
24. CodeIgniter simple login with sessions
Razvan Raducanu, PhD
 
Latihan form login
Latihan form login
Edy Sinaga
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
Wake Liu
 

Similar to 06 Php Mysql Connect Query (20)

4.3 MySQL + PHP
4.3 MySQL + PHP
Jalpesh Vasa
 
Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
Introtodatabase 1
Introtodatabase 1
Digital Insights - Digital Marketing Agency
 
Php summary
Php summary
Michelle Darling
 
Introduction to php database connectivity
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
P H P Part I I, By Kian
P H P Part I I, By Kian
phelios
 
Ubi comp27nov04
Ubi comp27nov04
mohamed ashraf
 
05 File Handling Upload Mysql
05 File Handling Upload Mysql
Geshan Manandhar
 
Download It
Download It
webhostingguy
 
Php 2
Php 2
tnngo2
 
veracruz
veracruz
tutorialsruby
 
veracruz
veracruz
tutorialsruby
 
veracruz
veracruz
tutorialsruby
 
veracruz
veracruz
tutorialsruby
 
Web Security - Hands-on
Web Security - Hands-on
Andrea Valenza
 
Database presentation
Database presentation
webhostingguy
 
Presenter manual php and mysql with cms (specially for summer interns)
Presenter manual php and mysql with cms (specially for summer interns)
XPERT INFOTECH
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivity
Mouli Chandira
 
Mysql & Php
Mysql & Php
Inbal Geffen
 
Ad

More from Geshan Manandhar (20)

How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
build-with-ai-sydney AI for web devs Tamas Piros
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
Are logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
Moving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
Adopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
Things i wished i knew as a junior developer
Things i wished i knew as a junior developer
Geshan Manandhar
 
Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
Embrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
A simplified Gitflow
A simplified Gitflow
Geshan Manandhar
 
How to become a better software company technically
How to become a better software company technically
Geshan Manandhar
 
Things I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
Message Queues a basic overview
Message Queues a basic overview
Geshan Manandhar
 
Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
Drupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgit
Geshan Manandhar
 
Drupal 7 install with modules and themes
Drupal 7 install with modules and themes
Geshan Manandhar
 
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
build-with-ai-sydney AI for web devs Tamas Piros
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
Are logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
Moving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
Adopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
Things i wished i knew as a junior developer
Things i wished i knew as a junior developer
Geshan Manandhar
 
Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
Embrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
How to become a better software company technically
How to become a better software company technically
Geshan Manandhar
 
Things I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
Message Queues a basic overview
Message Queues a basic overview
Geshan Manandhar
 
Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
Drupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgit
Geshan Manandhar
 
Drupal 7 install with modules and themes
Drupal 7 install with modules and themes
Geshan Manandhar
 
Ad

Recently uploaded (20)

FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 

06 Php Mysql Connect Query

  • 1. PHP Day 06 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com http://www.php.net http://www.mysql.com
  • 2. PHP – MYSQL Functions $resource_link = mysql_connect ( “server_name”, “user_name”, “password”); - Open a connection to a MySQL Server. mysql_select_db ( “data_base_name”, $resourece_link ); - Select a MySQL database mysql_query ( $query, $resourse_link); - Send a MySQL query to execute
  • 3. PHP – MYSQL Functions mysql_fetch_row ( resource $result ); - Get a result row as an enumerated array. mysql_fetch_array ($result, RESULT_TYPE); - Fetch a result row as an associative array, a numeric array, or both. mysql_num_rows ( resource $result ); - Get number of rows in result.
  • 4. PHP – MYSQL Functions mysql_affected_rows (); - Get number of affected rows in previous MySQL operation. mysql_error ( $resource_link ); - Returns the text of the error message from previous MySQL operation. mysql_close ( $resource_link ); - Close MySQL connection.
  • 5. Insert the User form field values to tbl_users Assumed the form has been submitted with action insert_user_process and method post. db_conn.php <?php $db['host'] = &quot;localhost&quot;; $db['user_name'] = &quot;root&quot;; $db['pass_word'] = &quot;&quot;; $db['name'] = &quot;php_class_db&quot;; $connection = mysql_connect ($db['host'], $db['user_name'],$db['pass_word']); if(!$connection){ die(&quot;Error connecting to the database server&quot;); } $db_name = mysql_select_db($db['name'], $connection); ?>
  • 7. The easy STATIC insert “ INSERT INTO tbl_user_test ( user_login, pass_word, address, email, gender, heard_from, newsletter, created_on, modified_on ) VALUES ('&quot;.$fdata['user_login'].&quot;', '&quot;.$fdata['pass_word'].&quot;', '&quot;.$fdata['address'].&quot;', '&quot;.$fdata['email'].&quot;', '&quot;.$fdata['gender'].&quot;', '&quot;.$fdata['heard_from'].&quot;', '&quot;.$fdata['newsletter'].&quot;', '&quot;.$fdata['created_on'].&quot;', '&quot;.$fdata['modified_on'].&quot;');”;
  • 8. Insert user function function insert_user_to_db($fdata){ global $connection; $tbl_name =&quot;tbl_user_test&quot;; //INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); $query = &quot;INSERT into $tbl_name (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= $key.&quot;)&quot;; } else{ $query .= $key.&quot;, &quot;; } }//could have done it with array_keys($fdata); … Continued
  • 9. Insert user Function $query .= &quot; VALUES (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= &quot;'$value'&quot;.&quot;);&quot;; } else{ $query .= &quot;'$value'&quot;.&quot;, &quot;; } } $result = mysql_query($query, $connection); if (!$result) { return 0; } else { return 1; } } Full code at: day06\insert_user_process.php
  • 10. Read some users from database
  • 11. Function show users Code at day06\show_users.php
  • 12. Output of show users
  • 14. Upgrade your Login System Create database with db desiger4 and export with use of PHPMyAdmin. Authenticate a user to the login system user select * from $tbl_name where user_login = $fdata[‘user_login’]; Then compare password if it matches login else do not login. if($row[‘pass_word’] == $fdata[‘pass_word’]){ Login } Maintain session very well.