How to Insert Data Into Database from a Form | PHP – MySql Tutorial for Beginners


KuberRuimte , South Africa – A terrible experience, steer clear – Horrible technical support, takes weeks to get a response. Rued representatives. Several billing errors. You are better off taking your business elsewhere.


https://youtu.be/78RUaIe4X0A
How to Insert Data Into Database from a Web form | PHP – MySql Tutorial for Beginners. Learn to Insert data into Database using Xampp/Wamp.

Thanks For Watching Our Video. Please Like And Suscribe Our Channel For more. 🙂

EasyLearn

46 Comments
  • Hello Deutschland
    Posted at 05:55h, 30 November

    i have error in { echo"<h3> Student's data is inserted successfully </h3> } can you explian it Please Please

  • Shaik Firasat Ali
    Posted at 12:50h, 17 March

    Good vedio it really helped me in my project.
    i got inspired.😊😊😊

  • Yash Lakha
    Posted at 14:56h, 20 March

    can I get the source code used in the video?

  • Evan Higgins
    Posted at 18:11h, 31 March

    Nothing happens when I press submit. No new information is inserted into my database 🙁

  • fah173
    Posted at 03:31h, 17 April

    how can i contact you

  • Sirch
    Posted at 05:51h, 20 April

    Thank your for the tutorial. Only ran into one problem but saw that you answered it in someones comment. Thanks.

  • 98055 22098
    Posted at 21:46h, 03 May

    not working

  • Rui Maria Vaz Pinto Rebelo de Andrade
    Posted at 12:09h, 07 May

    Hello. What im doing wrong? when I submit it returns to same page and data was not inserted in phpmyadmin.

    <?php$con = mysqli_connect("localhost","root","","alenbaga");if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }if(isset($_POST['submit'])){
     $num = $_POST['num_trab'];
     $nome = $_POST['nome'];
     $empresa = $_POST['empresa'];
     $sexo = $_POST['sexo'];
     $ano = $_POST['ano'];
     
     $query = "insert into employee (num_trab,nome,empresa,sexo,ano) values('$num','$nome','$empresa','$sexo','$ano')";
     if(mysqli_query($con,$query))
     {
      echo"<h3>Data was inserted successfully</h3>";
     }}?>

  • Trimay Wear Plate Ltd
    Posted at 20:50h, 24 May

    can I have the code?

  • Neville Koul
    Posted at 19:56h, 03 June

    thank you . nice video

  • Colin Nolan
    Posted at 00:00h, 19 June

    Great video and it helped me so much. You made it look so easy!!Kindest Regards

  • Remix Studio
    Posted at 11:27h, 29 June

    Can you tell me whats wrong with this code.
    //A.html
    <html>
    <body>
    <form name="form1" method="post" action="b.php">
    <table border=1>
    <tr>
    <td colspan="2">Submit to Datatbase</td>
    </tr>
    <tr>
    <td>Name:</td><td><input type="text" size="50" name="name" maxlength="50"></td>
    </tr>
    <tr>
    <td>Address:</td><td><input type="text" size="50" name="address" maxlength="50"></td>
    </tr>
    <tr>
    <td>Phone:</td><td><input type="text" size="50" name="phone" maxlength="50"></td>
    </tr>
    <tr>
    <td colspan="2"><button type=""submit">Submit</button></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    ———————————————————————————————————————————————————————————–
    //b.php
    <?php
    $db= mysql_connect("localhost","root","");
    if(!$db)
    exit("Error-could not connect to MySQL");
    $er=mysql_select_db("db_college");
    if(!$er)
    exit("Error-could not select the database.");

    $name=$_post["name"];
    $address=$_post["address"];
    $phone=$_post["phone"];

    $qry="insert into tbl_student(name,address,phone) values('$name','$address','$phone')";
    if(mysql_query ($qry))
    echo"successfully inserted";

    ?>

  • rhea mykah raterta
    Posted at 15:47h, 07 July

    Hi! can you please check my code. I have an error.
    Notice: Undefined index: fname in C:xampphtdocsconnect.php on line 42
    Notice: Undefined index: roll in C:xampphtdocsconnect.php on line 43
    Notice: Undefined index: result in C:xampphtdocsconnect.php on line 44

    <html>
    <head><title>Medical Data</title></head>
    <body background="image.jpg">
    <body>
    <form action="connect.php" method="post">
    <marquee><h2>WELCOME!!!</h2></marquee>
    <center><table border="1" width="400" height="300">
    <tr>
    <td colspan="5" align="center" bgcolor="white">Performance Appraisal</td>
    </tr>
    <tr>
    <td align="right" >Name:</td><td><input type="text" name="name"></td>
    </tr>
    <tr>
    <td align="right">Father's name:</td><td><input type="text" name="name">
    </tr>
    <tr>
    <td align="right">Roll No.:</td><td><input type="text" name="name">
    </tr>
    <tr>
    <td align="right">Result:</td><td><input type="text" name="name">
    </tr>
    <tr>
    <td colspan="5" align="center"><input type="submit" name="submit" value="submit"></td>
    </tr>

    </table></center>
    </form>
    </body>
    </html>

    <?php

    mysql_connect("localhost","root","") or die("not connected");
    mysql_select_db("student") or die("no db found");

    if(isset($_POST['submit'])){
    $name=$_POST['name'];
    $fname=$_POST['fname'];
    $roll=$_POST['roll'];
    $result=$_POST['result'];

    $query = "insert into data(name,fname,roll,result)values('$name','$fname','$roll','$result')";
    if(mysql_query($query))
    {
    echo"<h3>Employee's data is inserted successfully</h3>";
    }
    }
    ?>

    Thank you 🙂

  • NEIL DAGLE
    Posted at 02:37h, 13 July

    this is a great job man… keep it up… tks.

  • LK WEB SOLUTIONS
    Posted at 03:15h, 24 August

    Can you send me php source???
    Please send me.
    Thanks
    Lkprajapat108@Gmail.com

  • abirame selvendran
    Posted at 02:04h, 27 August

    i have error *"if(isset($_POST['save'])
    { " here "{" this one is unexpect * can you explian it please

  • neoramyeon
    Posted at 04:16h, 02 September

    where to save this file??

  • Timi Odeyemi
    Posted at 20:27h, 05 October

    how can i make a link to automatically download using xampp?

  • Temyong Tem
    Posted at 12:38h, 08 October

    thanks a lot bro for this tutorial ….and plss can you upload other tutorial for view record, update, delete fucntion aslo search record plllss. i need it to my final project

  • AMINUL HUSSAIN
    Posted at 06:33h, 11 October

    i have an error
    syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in line if(isset……….)

  • Charles Baulot
    Posted at 06:29h, 19 October

    Thanks very much !

  • SS Tech & Creations
    Posted at 19:13h, 27 October

    How to create mysql database, table and insert da…: http://youtu.be/8mSiXwo4jZU

  • Teddy Ngeene
    Posted at 11:08h, 31 October

    very helpful

  • Prem ICFA
    Posted at 08:42h, 07 November

    Showing error Parse error: syntax error, unexpected 'echo' (T_ECHO) in {
    echo "<h2> Student's data is inserted successfully </h2>"

  • md najim alam
    Posted at 22:51h, 07 November

    great bro…….

  • Patrick Day
    Posted at 08:06h, 17 November

    these tutorials suck i don't want to read would rather have a narrated tutorial

  • Tshehla Thabang
    Posted at 02:24h, 18 November

    Most of the stuff you did was unnecessary.

  • Keith Au
    Posted at 14:30h, 01 December

    Yes。Thanks a lot Duke。for posing it at all。

  • Mohammad Hamdan
    Posted at 11:12h, 10 December

    thank You

  • Ξxodus
    Posted at 19:46h, 13 December

    im having a hell of a time trying to get anything to work

  • Y T reddy
    Posted at 16:17h, 25 December

    i have error Parse error: syntax error, unexpected end of file in C:xampphtdocsconnection.php on line 44
    can you explain please

  • Manoj Mahajan
    Posted at 07:43h, 09 February

    i have error in

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

    <html>
    <head><title>student data</title></head>
    <body>
    <form action="connect.php" method="POST">
    <h2>WELCOME…….!!!!!</h2>

    <table border="1">
    <tr><td colspan="2">Student Informations</td></tr>
    <tr>
    <td>Name:</td><td><input tpe="text" name="name"></td>
    </tr>
    <tr>
    <td>Father Name</td><td><input tpe="text" name="fname"></td>
    </tr>
    <tr>
    <td>Roll No</td><td><input tpe="text" name="roll"></td>
    </tr>
    <tr>
    <td>Result</td><td><input tpe="text" name="result"></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" name="submit" value="submit"></td>
    </tr>
    </table>

    </form>
    </body>
    </html>
    <?php

    $servername = "localhost";
    $username = "root";
    $password = "";

    $mydb = new mysqli($servername, $username, $password);

    if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $fname = $_POST['fname'];
    $roll = $_POST['roll'];
    $result = $_POST['result'];

    $query="Insert into data (name,fname,roll,result) value('$name','$fname','$roll','$result')";
    if(mysql_query($query))
    {
    echo "<h3>Student's data is inserted successfully</h3>";
    }

    }

    ?>

    what is the mistake please please

  • Yamraj p
    Posted at 21:57h, 10 March

    Not able to insert data in database , plz chk my query – $query = "INSERT INTO login_page(username,password) VALUES ('$username','$password')";

  • Ranjeet Deshmukh
    Posted at 04:50h, 27 March

    can u please give me the link of the last video. how to create database & making connection

  • HEART HACKER JR
    Posted at 19:35h, 31 March

    GREAT….👌👌👌plz put video about on retrieving data from database

  • getenet dires
    Posted at 07:41h, 08 May

    when i search to localhost:80/ it say can,t reached what is wrong

  • David Hernandez
    Posted at 22:50h, 10 May

    It didn't completely fix my problem I had but out of all my searches, this did really point me in the right direction. Thanks!

  • Humayun Nasir
    Posted at 07:31h, 07 July

    Great thanks alot

  • Arvinzeres Ampogi
    Posted at 08:09h, 01 August

    whats that little box thing after the code $_POST

  • S KF
    Posted at 13:43h, 09 August

    Great jop bro thanks.

  • jess jesse
    Posted at 23:20h, 24 August

    1: php youtube account login tricks ! Txt editing = mankind 666 ! Wrong used for own profit ! It demonicall alter -ego disorders !

  • jess jesse
    Posted at 23:21h, 24 August

    2: the 666 mankind & his keyboard txt editing file save storage ! Wrong dude !

  • Firoz Mahmud
    Posted at 13:18h, 02 September

    where is the problem?

    <html>
    <title>Form</title>
    <style>
    </style>

    <body background="image.jpg">
    <marquee><h1 style=color:red >Welcome To Registratin Form</h1></marquee>
    <font face="Arial" color="black" size="5px"</font>

    <form "action=connect.php", method="post">
    Name <input type="text" name="Name">
    <div><br>
    <input type="radio" name="gender" value="male">Male
    <input type="radio" name="gender" value="female">Female
    </div>
    <br>
    <select>
    <option> Birth Date </option>
    <option>1990</option>
    <option>1994</option>
    </select>
    <br><br>
    <b>User Name</b> <input type="text"></input>
    <b>Password</b> <input type=password></input>
    <br><br>
    <input type="checkbox">SSC
    <input type="checkbox">HSC
    <input type="checkbox">BSC
    <input type="checkbox">MSC
    <br><br>
    <input type="submit" value="Register" name="Submit"><br><br>
    <input type="reset" value="Reset" name="clear"

    </form
    </body>
    </html>

    <?php
    mysql_connect("localhost", "root") or die("Not Connected");
    mysql_select_db("Registration From") or die("No db Found");

    if(isset($_POST[Submit])){

    $name= $_POST['name'];
    $male= $_POST['male'];
    $female= $_POST['female'];
    $date= $_POST['date'];
    $user_name= $_POST['user name'];
    $password= $_POST['password'];
    $ssc= $_POST['ssc'];
    $hsc= $_POST['hsc'];
    $bsc= $_POST['bsc'];
    $msc= $_POST['msc'];

    $query = "inser into data(name,male,female,date,user_name,password,ssc,hsc,bsc,msc) value('$name','$male','$female',
    '$date','$user_name','$password','$ssc','$hsc','$bsc','$msc')";

    if(mysqul_query($query)
    {
    echo "data inserted successfull";

    }

    }
    ?>

  • MOJO 24/7
    Posted at 07:15h, 30 October

    thank u its working good .do more tutorials in crurd applications.

  • Tan Mari
    Posted at 07:45h, 03 November

    Thnks a lot. Background music kept me awake and focused

  • sagar TM
    Posted at 19:17h, 14 November

    Upload next delete update videos