• Wednesday , 18 October 2017

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

Code Canyon



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

Original source

3d Ocean

Related Posts

49 Comments

  1. Jardell E
    July 8, 2017 at 02:23

    good tutorial, but the "watch updated version" is blocking the screen.

  2. vishal rajput
    July 8, 2017 at 02:23

    what is this mysqli……..it is creating many difficulties

  3. Jap Jap
    July 8, 2017 at 02:23

    when i use your codes this the result:

    Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:xampphtdocsgsdemo.php:8 Stack trace: #0 {main} thrown in C:xampphtdocsgsdemo.php on line 8

  4. Ehsan Ansari
    July 8, 2017 at 02:23

    I am getting the following when execute the connection:

    Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found. in C:xampphtdocstutorialsphpbasicsdemo.php on line 9

    My code is:
    <?php
    //defining constants syntax: define('constants', 'value');
    define('DB_NAME', 'mysql');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_HOST','localhost');

    //connecting the host
    $link = mysql_connect(DB_USER, DB_PASSWORD, DB_HOST);

    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!';

    ?>

    Please help

  5. Constance Toh
    July 8, 2017 at 02:23

    Hi, I dont know why it show me the whole php code for me… ?
    <?php

    DEFINE ('DB_USER', 'root');
    DEFINE ('DB_PASSWORD','');
    DEFINE ('DB_HOST','localhost');
    DEFINE ('DB_NAME','aptc');

    $dbc =mysql_connect(DB_NAME,DB_HOST,DB_PASSWORD,DB_USER)

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

    $db_selected = mysql_select_db(DB_NAME,$dbc);

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

    }

    echo 'Connected Successfully';
    ?>

  6. T Design Studios
    July 8, 2017 at 02:23

    Do you have a tutorial on how to create a form that uploads to an SQL database and sends a confirmation e-mail?

  7. nany kaur
    July 8, 2017 at 02:23

    what is problem with my code:
    <?php
    define('DB_NAME','info');
    define('DB_USER','usename');
    define('DB_PASSWORD','');
    define('DB_HOST','localhost');
    $link=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
    if(!$link)
    {
        die("couldnt connect". mysql_error());
        
    }
    $db_selected=mysql_select_db(DB_NAME,$link);
    if(!$db_selected)
    {
        die("couldnt connect" . DB_NAME . ":" mysql_error());
        
    }
    echo"connected successfully";
    ?>

  8. John Morris
    July 8, 2017 at 02:23

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

  9. Kim Vojensky
    July 8, 2017 at 02:23

    I've followed tutorial exactly and love it.  But on my server side, there is no data that is showing up?  Any suggestions?

  10. bandora
    July 8, 2017 at 02:23

    Thanks for the tutorial, but I have a quick question for you, if I want to have more than one input in the form (lets say first name and last name), how can I differentiate between those two? Will I need something like $value1 = $_POST['input1']; and $value2 = $_POST['input2']; and do the SQL query for those inputs?

  11. ʇɐɔʎɯpǝʞɔıʞ
    July 8, 2017 at 02:23

    thanks you i have a massive grin on my face :)))))

  12. rockhopper123452
    July 8, 2017 at 02:23

    my code returns " MySQL returned an empty result set (i.e. zero rows). (Query took 0.0008 sec)

  13. Jomar Rodenas
    July 8, 2017 at 02:23

    What is the problem with my code?

    <?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();
    ?>

  14. Sumit Singh
    July 8, 2017 at 02:23

    thanks done bro 😉

  15. Carlbenn Ferrancullo
    July 8, 2017 at 02:23

    how can i fix these:
    Undefined index: input1 in C:wampwwwdemo.php on line 20

  16. Nini Man
    July 8, 2017 at 02:23

    How do i fix this? 😮 "Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:wampwwwdemo.php on line 8"

  17. Sinister5ixX
    July 8, 2017 at 02:23

    I get the error "Warning: mysql_select_db() expects parameter 2 to be resource, object given in C:wampwwwcontact.php on line 14"

  18. Gian Carla Tolentino
    July 8, 2017 at 02:23

    i wish i could have a better look in line 21 ..  please!

  19. dignyochick
    July 8, 2017 at 02:23

    4 years later, this is EXACTLY what I need. Thank you very much sir!

  20. Ricardo Arteaga
    July 8, 2017 at 02:23

    it said i cant use form1, and iono why and how to fix error.

  21. Jeya Prakaz
    July 8, 2017 at 02:23

    Hai Sir … Thank you very much it was very useful for me…but please help me to add one more tab like input 1.Please sir !

  22. Eddie Cardona
    July 8, 2017 at 02:23

    Thank You John U tha Man Helped me out Big Time

  23. Fábio Rocha
    July 8, 2017 at 02:23

    Thanks so much. I am heading to your site now.

  24. Fábio Rocha
    July 8, 2017 at 02:23

    Ok, I've just watched your final video (4/4) and I got it. Can you please post the link for the video "advanced form construction" you have mentioned.
    Thank you
    Fábio

  25. John Morris
    July 8, 2017 at 02:23

    $value = $_POST ['input1'];
    $value2 = $_POST['input2'];
    $sql = "INSERT INTO demo (input1, input2) VALUES ('$value', '$value2')";

    That's a very rudimentary way of doing. I'd loop through the $_POST array and build everything dynamically. Also, this isn't secure at all. Dropping $_POST data straight into your database is a huge no-no. Nowadays you use prepared statements. Go to my site (in description) /mysql if you just want all the answers.

  26. Fábio Rocha
    July 8, 2017 at 02:23

    Nice tutorial.
    My question is:
    You've got the following code:
    ==========
    $value = $_POST ['input1'];
    $sql = "INSERT INTO demo (input1) VALUES ('$value')";
    ==========

    So, considering i've got input2, input3 in my database, how do I send those multiples values to my database?
    Appreciate your time.

  27. senntenial
    July 8, 2017 at 02:23

    this is awesome, thanks a ton.

  28. John Morris
    July 8, 2017 at 02:23

    Best place to go to see them all is the playlist here:

    /watch?v=J2-neLr7MXM&list=PL530D33D6E548481F

  29. Thierry Doré
    July 8, 2017 at 02:23

    Hi there and thanks a lot for your tutorails.
    Could you put a link to the next 'episode' ? because i can't find the last part .

    Thanks

  30. John Morris
    July 8, 2017 at 02:23

    Well, I don't have this code anymore otherwise I would have it linked up on my website. So, I don't have anything to send you.

    The thing is, though, you say you're getting "syntax" errors. I'm going to push back and say you need to figure those out. If you were getting some other kind of error… ok

    But, syntax is really basic PHP. And, my goal is to teach you the code… not just give it to you. So, I feel like you need to figure out the syntax errors. I think I'd be doing you a dis-service.

  31. Shane Bloem
    July 8, 2017 at 02:23

    iv raped google, on the verge of going to a library!

  32. Shane Bloem
    July 8, 2017 at 02:23

    Please could you send me the complete html and php as well as detailed info on how to link up the php to mysql. reason is because i get syntax errors when copying ur script off ur video, would be much appreciated and would be a noble worrier for helpful programming expertise if ur interested. kind regards contact +2776 147 9134 only or respond to my query

  33. Torrey Holman
    July 8, 2017 at 02:23

    I did a test demo the exact way you did. I was taken to a blank page on submit…

  34. Edriss Jabini
    July 8, 2017 at 02:23

    thanks john

  35. MemoriesByTheSmile
    July 8, 2017 at 02:23

    Ok, I am following along, but is there anywhere that you explain how to put in a success message? Like, once someone uses my form and the information has been successfully submitted, they should get a message like "thank you for submitting." Do you explain that anywhere? Or can you tell me how to do that PLEASE? I'm so close to having this all worked out!!!

    Thank you

  36. Ace Best
    July 8, 2017 at 02:23

    oh, one more thing. My form has multiple values, and I have described them carefully on the php file.

  37. Ace Best
    July 8, 2017 at 02:23

    I have followed your instruction carefully step by step. But when I tried to submit my form,there's a undefined index notice on my browser, and the input didn't get to mysql. where did I go wrong? I use dreamweaver as an editor, and xampp package. Thanks bro.

  38. John Morris
    July 8, 2017 at 02:23

    Your code was missing an = sign. It should be name="input1"

  39. John Morris
    July 8, 2017 at 02:23

    Is your form field named "input1". If not, you'll need to change $_POST['input1'] to whatever the name of your form field is.

  40. ktdlrsr
    July 8, 2017 at 02:23

    I made a form in html, then I use action="sampledb.php" method="post".. When I input data from the html page, the data won't show in mysql database..

  41. Nancy Nyakwada
    July 8, 2017 at 02:23

    this videos helped me a lot with my assignment.

  42. lynchite
    July 8, 2017 at 02:23

    Fatal error: Function name must be a string in / ***/script.php on line 27

    it was working up until I did the sql query??

  43. bobo692003
    July 8, 2017 at 02:23

    Excellent tutorial. I was having some issues on a school assignment and this tutorial straightened it right up. Thanks!

  44. Jack Ziesing
    July 8, 2017 at 02:23

    do you have to upload the image with a name?

  45. Jeremy van Vliet
    July 8, 2017 at 02:23

    Hey dude, what a great video-serie it is!
    Thank you for your great way of explaining, however….. the demo.php (i've called it save.php) doesn't do anything! it just stays blank, no echo and no error…. could you help me out?
    What information do you need?

  46. benamou elkhayer
    July 8, 2017 at 02:23

    the same as me bro

  47. Vandole
    July 8, 2017 at 02:23

    the php files in question are demo-form.php and demo.php and are currently sitting on my desktop

  48. Vandole
    July 8, 2017 at 02:23

    i have a really bad professor that didn't explain this well enough in class, but since I am watching these videos i'm understanding it more, but where do i put my php files that i'm making for MySQL so that i can browse them via localhost? i've yet to find anything that can answer this question.

Leave A Comment

You must be logged in to post a comment.