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




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


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

  1. 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

  2. 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

  3. 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';
    ?>

  4. 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";
    ?>

  5. 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?

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

  7. 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"

  8. $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.

  9. 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.

  10. 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.

  11. 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

  12. 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

  13. 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.

  14. 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?

Leave a Reply