• Monday , 20 November 2017

PHP Tutorial 28 – MySQL Inserting Data (PHP For Beginners)

Code Canyon



This tutorial takes a look at how to insert data into a MySQL Table and specify which fields to insert data into. There is no example of using this to insert …

Original source

3d Ocean

Related Posts

45 Comments

  1. Mohamed Ahamed Sabeer
    September 14, 2017 at 02:15

    It doesn't show no error but it is insert the values

  2. Inno Dominic Ramos
    September 14, 2017 at 02:15

    Thank you so much chris, I've learned a lot from you, wherever you are good luck to you man 🙂

  3. mark aizen
    September 14, 2017 at 02:15

    it helped alot thnks

  4. Aymane Biri
    September 14, 2017 at 02:15

    Man thank you so much i've been searching for some tutorials like this for so long

  5. manuel nunez
    September 14, 2017 at 02:15

    Hi, can you please check why my code keeps on giving me "not inserted" error.
    I tried to check the syntax but still the same error.

    <?php
    $con = mysqli_connect('********', '*********', '********');

    if (!$con) {
    echo 'Not connected to Server';
    }
    if(!mysqli_select_db($con,'***********'))
    {
    echo 'Database not selected';
    }
    $fname = $_POST['fname'];
    $mname = $_POST['mname'];
    $lname = $_POST['lname'];
    $position = $_POST['position'];
    $mobile1 = $_POST['mobile1'];
    $mobile2 = $_POST['mobile2'];
    $age = $_POST['age'];

    $sql = "INSERT INTO workers (fname, mname, lname, position, mobile1, mobile2, age,) VALUES ('fname','mname','lname','position','mobile1','mobile2','age')";

    if(!mysqli_query($con,$sql))
    {
    echo 'Not Inserted';
    }
    else
    {
    echo 'Inserted';
    }
    header("refresh:10000000; url=insertindex.html");

    ?>

  6. Gaming Block
    September 14, 2017 at 02:15

    hi

    it says Parse error: syntax error, unexpected T_VARIABLE in /home/a8326296/public_html/hub/index.html on line 8

    here is my code

    <?php

    $accounts = mysql_connect("mysql6.000webhost.com", "a8326296_profile", "***********")
    or die (mysql_error());

    mysql_select_dl("users", $accounts)

    $sql = "
    INSERT INTO users (username, password) VALUES('Chris', 'Pass123')
    ";

    mysql_query($sql, $accounts)

    ?>

  7. gaming obly
    September 14, 2017 at 02:15

    do you play cod4 (call of duty modern warfare 4)???
    🙂

  8. Elisa Pabilane
    September 14, 2017 at 02:15

    sir what if im using
    $accounts=mysqli_connect("localhost", "root", "password") or die (mysqli_error());

    mysqli_select_db("accounts", $accounts);

    the error is
    Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:wampwwwMySQL.php on line 4

  9. ImAwkward ButNotDeviant
    September 14, 2017 at 02:15

    please help… 
    Parse error: syntax error, unexpected end of file in C:xampphtdocsSampleinsertvalues.php on line 13

    <?php
    $con = mysql_connect("localhost","root","");

    if(!$con){
    die("can not connect".mysql_error());

    mysql_select_db("mydatabase",$con);

    $sql= "INSERT INTO mytable(user_id, firstname, lastname) VALUES('1','jaime','rivera')";

    mysql_query($sql,$con);

    mysql_close($con);

    ?>

    thanks!

  10. prav pravs
    September 14, 2017 at 02:15

    Hi brother…. your videos are very useful to me….
    I have one doubt that if we give data like this
    INSERT INTO user2 (USERNAME,PASSWORD,FIRST_NAME,LAST_NAME) VALUES('asdf', 'pwd'123', 'dasdsa', 'sdfsdfsd');
    it will truncate the password field upto pwd because php will take next ' as ending….how to overcome this problem….can you please clarify me this doubt….??
    thanku..

  11. Saba Bochikashvili
    September 14, 2017 at 02:15

    <?php
    $con = mysqli_connect("localhost","root","password","dbname") or die(mysql_error());
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    // Creating User
      $sql = "INSERT INTO `users2`
      (`ID`,
      `Username`,
      `Password`,
      `FirstName`,
      `LastName`) 
      VALUES (NULL,'user','password','fname','lname')";
    // Checking if created
      if (mysqli_query($con,$sql))
      {
      echo "User created successfully </br>";
      }
    else
      {
      echo "Error creating User: " . mysqli_error($con);
      }
    ?>  

    this is for guys "doesn't worked help me !". 🙂  
    didn't worked because there is new versions of mysql…
    and for mysql_connect i typed mysqli , and same on others…
    or maybe you have not finished your script, explame: forgoted ";" or something like that. 

  12. PSVR420
    September 14, 2017 at 02:15

    I spent 3 days trying to get this to work and yours is the only example that actually worked when i changed it to my details, thanks a lot, now to just get these fields into a user submittable form 😀

  13. Nikolaj Andrjoestsjenko
    September 14, 2017 at 02:15

    Dear Chris,

    Can you show us please how users can insert data to it, i mean with a <input type="text"> html input window.

  14. AtlasTheDestroyer
    September 14, 2017 at 02:15

    To all the people that it isn't working for use this code in your text editor: 

    <?php
    $accounts = mysql_connect("localhost", "root", "password")
    or die(mysql_error()); 
    mysql_select_db("accounts", $accounts);

    $sql="
     INSERT INTO users2 (Username, Password, FirstName, LastName) VALUES('Name', 'Password', 'FirstName', 'LastName')
    ";
    echo $sql;
    if (!mysql_query($sql, $accounts))
    {
    die('Error: ' . mysql_error());
    }
    echo "<h1> 1 record added to database </h1>";
    ?>

    A quick tip for your future studying; the 'echo $sql' shows you the process and if it fails you can fix it, this is called 'debugging' and that simple line will help you vastly.

  15. Tara Arya
    September 14, 2017 at 02:15

    Hi Chris, Your videos really helped me to clear my basics in php & mysql…thanks a lot!! 🙂

  16. Jenna Johnson
    September 14, 2017 at 02:15

    I noticed that he uses the word 'bracket' which I took for [] and he meant (). Works great now.

  17. khalid Qweder
    September 14, 2017 at 02:15

    Nice lesson.

  18. Pedro Rodrigues
    September 14, 2017 at 02:15

    people just skip the vide to 0:57 pls 🙂

  19. alisalman hussein
    September 14, 2017 at 02:15

    hi , sorry 2 bother but i have a problem in this video and the last one because  i did everything as u said since the first video i even downloaded the same porgram u showed in the tutorials and am using windows 7 ultimate 64-bit but in the last 2 videos technically i couldn't  even add a group to the ((accounts)) database using php , so i can't even modify it or add values to it, the question is what do u think that the problem is?? thank u so much………….

  20. Tejas Lodaya
    September 14, 2017 at 02:15

    Hey, I tried to link the php page using GET method. And allowed the user to enter the username password etc using an html form.. I am able to link it to the php page which has the mysql query connected to it.. That's not working.. I mean I use the username and password types by the user and save it to the database.. Not working..

  21. Deepak Chaudhary
    September 14, 2017 at 02:15

    Hi,
    Good Job …!!

    I m new for PHP but i m stucked at a problem ..

    how to update value?
    if user enters ID than rest valuse update otherwise it will insert into new row with different ID?

    thanks in advance

  22. Mobile Health eRecords
    September 14, 2017 at 02:15

    Still not connecting to my database. I really wish I could figure this out. 

  23. holysacrist85
    September 14, 2017 at 02:15

    thank you for the Tutorials …..

  24. Austin Massee
    September 14, 2017 at 02:15

    "I'm not going to lie and say I was like doing exams…
    …[I've] just been playing Modern Warfare 3 the whole time and it's, ugh, its so good."  : ) made me laugh. 

    Thanks for teaching me php in a day. : )

  25. Rajkumar Kasturiraj
    September 14, 2017 at 02:15

    Awesome tutorial…
    very much helpful for me to understand php.
    I surely recommend this for beginners..

  26. Parth Garg
    September 14, 2017 at 02:15

    though the browser doesnt show any error but my table is not updated
    why

  27. youssef fatih
    September 14, 2017 at 02:15

    hi thanks for your tut
    can you make a tutorial where i can read from .txt file and insert the data into mysql database

    this is my data:
    SEASON OF THE WITCH                            DONE
    RED DAWN                                                DONE
    ZERO DARK THIRTY                                   DONE
    THE HOBBITS                                            DONE
    THE BEST EXOTIC MARIGOLD HOTEL        DONE

    my database table is going to have 3 colones one for id one for movie one for done or not

  28. Matej Šuster
    September 14, 2017 at 02:15

    Amazing tutorials, thank you so much, this is an amazing time saver, everything works just just like you do it, thumbs up bro 🙂 

  29. TheAbbyLo
    September 14, 2017 at 02:15

    Wow when you cough like that in the middle of the tutorial when I am using earphones, volume loud…that's something. Please don't do that.

  30. anees qureishi
    September 14, 2017 at 02:15

    Thanks for the video man.

    I created the database using the PHP code and I am not getting any error but still the table is not created in phpMYAdmin..:(

  31. pritom borogoria
    September 14, 2017 at 02:15

    feeling happy………..

  32. Leo P
    September 14, 2017 at 02:15

    mysql_select_db("accounts", $accounts); you forgot the quotation

  33. rok dolinar
    September 14, 2017 at 02:15

    Sorted- there is a " missing behind "accounts.

    Sorry for spamming

  34. rok dolinar
    September 14, 2017 at 02:15

    Parse error: syntax error, unexpected 'INSERT' (T_STRING) in C:xampphtdocstutorialsdata.php on line 9

    $accounts = mysql_connect("localhost", "root", "dolinar")
    or die(mysql_error());
    mysql_select_db("accounts, $accounts);
    $sql= "
    INSERT INTO users2(Username , Password , First , Last) VALUES('Chris','pass123','Chris','Johnson')
    ";
    mysql_query($sql, $accounts);

    Can anyone help me?

  35. TheFake VIP
    September 14, 2017 at 02:15

    OMG… look at how many subscribers he has

  36. YourAnimation MC
    September 14, 2017 at 02:15

    Omg data is not being inserted in QAWHBES[FVKHBDJQBJLCDJVS;SL
    F,
    ]DM .V,

  37. Niki Avranov
    September 14, 2017 at 02:15

    check that "user2" is really your table name, cuz for Chriss it is "users".

  38. tommaso girotto
    September 14, 2017 at 02:15

    Thanx!

  39. Michael Odom
    September 14, 2017 at 02:15

    Hey, thanks for taking the time to make all these video tutorials! They are great.

  40. Amritpal S.
    September 14, 2017 at 02:15

    $db_connection = mysql_connect("localhost", "root", "") or die(mysql_error());

    mysql_select_db("accounts", $db_connection);

    $sql = "
    INSERT INTO user2 (USERNAME,PASSWORD,FIRST_NAME,LAST_NAME) VALUES('asdf', 'pwd123', 'dasdsa', 'sdfsdfsd')
    ";

    mysql_query($sql, $db_connection);

  41. Amritpal S.
    September 14, 2017 at 02:15

    which one it shud be? I am also facing same issue

  42. FnugzGaming
    September 14, 2017 at 02:15

    the mysql_connect(…) or die (mysql_error());
    is not working for me, no errors show up if i type the password wrong, so im not sure that i am even connected… maybe its the phpMyAdmin, config but i have no idea…
    any help?

  43. Ahmad Radi
    September 14, 2017 at 02:15

    Check your brackets { } or ( ).

  44. nevermore690
    September 14, 2017 at 02:15

    Sir Teachmecomputer can you make tutorial about making biometric in vb,net i love your tutorial and understand it. Hope you make a tutorial about vb,net biometric cause i cant find one tutorial about biometric in youtube thanks sir

  45. nevermore690
    September 14, 2017 at 02:15

    Hope so im sorry maybe i miss something .thanks bro

Leave A Comment

You must be logged in to post a comment.