• Sunday , 19 November 2017

How to Create an HTML Form That Stores Data in a MySQL Database Using PHP Part 2 of 4

Code Canyon



Watch the updated version of this tutorial here: https://www.youtube.com/watch?v=BmHLvUdkCA0&list=PL530D33D6E548481F&index=1 For more video …

Original source

3d Ocean

Related Posts

44 Comments

  1. Jeremy Boulerice
    July 7, 2017 at 02:20

    Great tutorials, but you talk a lot for no reason

  2. Ifan The Applicator
    July 7, 2017 at 02:20

    Thank you John Morris, your tutorials really help me a lot!!

  3. Gremz Maliberan
    July 7, 2017 at 02:20

    can't usewebsite: Access denied for user ''@'localhost' to database 'website'

  4. Edward Chien
    July 7, 2017 at 02:20

    On 7:44, I wasn't able to connect successfully. Where do I put my demo-form.php and demo.php files? Does it matter where I put them on my computer? Please advise. Thank you!

  5. Edward Chien
    July 7, 2017 at 02:20

    this is great! thank you john

  6. Nishan Thapa
    July 7, 2017 at 02:20

    U talk too much.

  7. derrik bosse
    July 7, 2017 at 02:20

    I did everything like you said, no errors, but the data is not getting uploaded to the database on phpmyadmin

  8. John Morris
    July 7, 2017 at 02:20

    Make sure to watch the updated version of this tutorial here: https://www.youtube.com/watch?v=BmHLvUdkCA0&list=PL530D33D6E548481F&index=1

  9. Muhammad Shakir
    July 7, 2017 at 02:20

    Demo-form.php

    <html>
    <body>

    <form action="demo.php" method="post">
    <p>
    </br>
    <label> Name: <input type="text" name="name">
    </br></br>
    <label> Submit This Query Please! <input type="submit" value="Go For It!">
    </p>
    </form>
    </body>
    <html>

    Demo.php

    <?php

    define('DB_NAME', 'form1');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_HOST', 'localhost');

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if(!$link)
    {
    die ('Could not Connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db(DB_NAME, $link);

    if(!$db_selected)
    {
    die('can't use ' . DB_NAME . ': ' .mysql_error()) ;
    }
    echo " Dang";

    $value = $_POST['name'];

    $sql = "INSERT INTO demo (name) Values ('$value')";

    if (!mysql_query($sql))
    {
    die('Error: ' . mysql_error());
    }

    mysql_close();
    ?>

    I don't know what's wrong in this code when i am trying to compile my code it says error in this line . i have no idea 

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

  10. Adrian Jones
    July 7, 2017 at 02:20

    Thank you so much for this series of videos! I'm definitely going to join. I like you teaching style. I'm having a problem and I'm hoping your still around to help out. I have my files live on my website. however i keep getting the error:
    Could not connect: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

    What does that mean? What do i have to do to fix it?

  11. Mark Jason Ortiz
    July 7, 2017 at 02:20

    dude, just wanna say that there are some codes or words that beginner might not understand. thats what i found out to your tutorial. But btw thank you for sharing your knowledge. Good day !

  12. bmoviestgams
    July 7, 2017 at 02:20

    I get this error when i run the demo.php

    Parse error: syntax error, unexpected '$link' (T_VARIABLE) 

  13. Sandun Bandara
    July 7, 2017 at 02:20

    You are awesome man!! you have goooooooooooood Fucher bye

  14. Jomar Rodenas
    July 7, 2017 at 02:20

    <?php

    define('DB_NAME', 'forms1');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_HOST', 'localhost');

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }

    $db_selected = mysql_select_db(DB_NAME, $link);

    if (!$db_selected) {
        die('Cant use ' . DB_NAME . ': ' . mysql_error());
    }     

    echo 'Connected Successfully';

    mysql_close();
    ?>
     NEED HELP

  15. Carlbenn Ferrancullo
    July 7, 2017 at 02:20

    how should i know if my code is correct.
    here is my code:
    demo.php

    <?php

    define('DB_NAME', 'forms1');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_HOST', 'localhost');

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }

    $db_selected = mysql_select_db(DB_NAME, $link);

    if (!$db_selected) {
    die('Can't use ' . DB_NAME . ': ' . mysql_error());
    }
    ?>

    demo-form.php

    <form action="demo.php" method="post" />
    <p>Input 1: <input type="text" name="input" /></p>
    <input type="submit" value="Submit" />
    </form>

    forms1

    — phpMyAdmin SQL Dump
    — version 3.3.9
    http://www.phpmyadmin.net

    — Host: localhost
    — Generation Time: Aug 19, 2014 at 07:05 AM
    — Server version: 5.5.8
    — PHP Version: 5.3.5

    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

    /!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT/;
    /!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS/;
    /!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION/;
    /*!40101 SET NAMES utf8 */;


    — Database: `forms1`

    CREATE DATABASE `forms1` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
    USE `forms1`;

    — ——————————————————–


    — Table structure for table `demo`

    CREATE TABLE IF NOT EXISTS `demo` (
      `ID` int(11) NOT NULL AUTO_INCREMENT,
      `input1` varchar(20) DEFAULT NULL,
      PRIMARY KEY (`ID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


    — Dumping data for table `demo`

    i really need to know if its right or if it is wrong…

  16. Anaya Martella
    July 7, 2017 at 02:20

    When I downloaded the demo from your actual site it didn't give me file with "demo-form.php" only a "demo.php" that is the form. It looks like you have six files open but I only have 5 that got downloaded. Help!!

    Also do you happen to have a tutorial on how to create those country, state, city selectors? That's really what I'm looking for but I'm hoping to make it myself with the knowledge you have provided.

    Let me know. 🙂

    Thanks,
    Naya

  17. VoidHost Minecraft
    July 7, 2017 at 02:20

    Hey in when I click save for the table it tells me that I need to enter a valid length  . What does that mean ?

  18. Sinister5ixX
    July 7, 2017 at 02:20

    Whenever I go to make the database I do the ID and input1. When I go to get the final product, I get "MySQL returned an empty result set (i.e. zero rows). (Query took 0.0000 sec)" and I don't know what to do.

  19. Amir Rahman
    July 7, 2017 at 02:20

    just a bullshit first of all i just came here to know how the informations stores into the database and you've described a lot about css and html (very disturbing) after that when i saw the main thing that i'm here for but its also not fully cleared you have done many things without showing how to

  20. Bernard Hayes
    July 7, 2017 at 02:20

    Yes here is my script.
    <?php
    define ('DB_NAME','newebay');
    define ('DB_USER','root');
    define ('DB_PASSWORD','bh05238');
    define ('DB_HOST','localhost');

    $link = mysql_connect('DB_HOST','DB_USER','DB_PASSWORD');

    IF (!$link) {
     die('Could not Connect :
        ' . mysql_error());
     
    }

    $db_selected = mysql_select_db (DB_NAME, $link);

    if (!$db_selected) {
    die('Can't use ' . DB_NAME . ': ' . mysql_error());

    }
    echo 'Connected successfully';

    ?>

    Thanks for the Fast response!

  21. Bernard Hayes
    July 7, 2017 at 02:20

    Hi John,  Love your videos so far.  Having a issue trying to get php to connect to mysql.  I keep getting this message. "php_network_getaddresses: getaddrinfo failed: Name or service not known".  I think the issue is the 'DB_HOST'.  I verified using mysql workbench that its name is local host.  I even tried putting the port number into the variable 'DB_HOST' = 'localhost:3306' and still didn't work.  What do you suggest?

  22. LikeNeverBefore dotInfo
    July 7, 2017 at 02:20

    WHY do you FORCE people to join??  WHEN did free stop being free??
    That's my passion – making free things free.

  23. Jack Chan
    July 7, 2017 at 02:20

    why is the DB_NAME forms1 and not demo

  24. michael habib
    July 7, 2017 at 02:20

    Hello, you are an awesome man, here is my problem when i enter anything into the input1, it gets me to the demo.php page 🙁 please help

  25. Matt Man
    July 7, 2017 at 02:20

    Hi, when I browse my demo.php. I get a blank page 🙁 please help! I don't know what is the problem! I had been following every single step! Many thanks!

  26. Pete J. Ruiz, Jr.
    July 7, 2017 at 02:20

    I keep getting that it's failing….i'm not sure what i'm doing wrong….looks like it's not finding my table, idk….hmmm….ill keep trying….good video….

  27. mhawn999
    July 7, 2017 at 02:20

    @Justin Emerson
    If you delete the function he wrote in there that is called $value=$_POST['input1'];
    and then where he has the next line of code stating $sql = "INSERT INTO demo (input1) VALUES ('$value'); and change it to $sql = "INSERT INTO Pledge (ID, Names) VALUES ('','$_POST[input1]')";
    then it should work. Just remember that you need to add security to something like this and if you don't it is very easy to retrieve the information in your box by simply putting a retrieve code.

  28. David Ukwuoma
    July 7, 2017 at 02:20

    hey John I'm having a little problem with my form processing, don't know if you can help me out. I'm tired of debugging.

  29. Justin Emerson
    July 7, 2017 at 02:20

    My info isn't showing up in my database. I get a new ID number but there is nothing in INPUT1. I watched your videos twice now and I can't seem to figure it out.

  30. Reyna Marie Dael
    July 7, 2017 at 02:20

    I've been watching your tutorials.. well, thanks a lot. ur really great 😀

  31. Dollie Swartwood
    July 7, 2017 at 02:20

    Get hosting account for just 1 cent at hostgator using coupon "1centaprlmay2013".

  32. Jim .Bob
    July 7, 2017 at 02:20

    phpMyAdmin.

  33. bj nilo
    July 7, 2017 at 02:20

    Hi sir is that in Libreoffice database?

  34. jese reyes
    July 7, 2017 at 02:20

    John could you please send me a link to your demo php file if still available. Thanks!

  35. Navneet Jha
    July 7, 2017 at 02:20

    where is the source code of this video

  36. jeng cua
    July 7, 2017 at 02:20

    hi John, I have a question Where can I find the PHP codes where you are showing define ('DB_name', demo') on my form I indicated ID, Login and Password (3 columns) but I do not know where can I find these code that you are showing PHP

  37. Mark Caspillo
    July 7, 2017 at 02:20

    what software did you use to construct html?

  38. Vanderkloes
    July 7, 2017 at 02:20

    Dear John,
    Can you tel me why i get the message cant use database

    Thanks From Holland By Jan.

  39. Chetankumar Chandak
    July 7, 2017 at 02:20

    can i have the link to the demo.php file??

  40. tony hoss
    July 7, 2017 at 02:20

    this is superb keep making tutorials brill!

  41. MrPlakeO
    July 7, 2017 at 02:20

    you're awesome!!!!

  42. John Morris
    July 7, 2017 at 02:20

    @sli313 Yeah. No problem! 🙂

  43. Dulan Jansze
    July 7, 2017 at 02:20

    @JohnMorrisVideo ahh! thanks so much 🙂 this videos helped me alot once again thanks very much!

  44. John Morris
    July 7, 2017 at 02:20

    @sli313 On line #7, you have a $ in front of the mysql_connect() function. Remove that and you should be good. 🙂

Leave A Comment

You must be logged in to post a comment.