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




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 …

Original source


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

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

    ?>

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

  3. Hello I Have An Error ……….Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:xampphtdocsselimconnect.php:33 Stack trace: #0 {main} thrown in C:xampphtdocsselimconnect.php on line 33

  4. can you check my codes please 🙂

    <html>
    <head><title>Student's Data</title></head>
    <body background="Image.jpg">
    <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="grey">Student's Information</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"></td>
    </tr>
    <tr>
    <td align="right">Roll No.:</td><td><input type="text" name="name"></td>
    </tr>
    <tr>
    <td align="right">Result:</td><td><input type="text" name="name"></td>
    </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>Student's data is inserted successfully</h3>";
    }
    }

    ?>

    theres a problem between the line

    Notice: Undefined index: fname in C:xampphtdocsstudentconnect.php on line 38

    Notice: Undefined index: roll in C:xampphtdocsstudentconnect.php on line 39

    Notice: Undefined index: result in C:xampphtdocsstudentconnect.php on line 40

  5. Hey I have written exactly what u told in the video & its working also but the prob is that it is not getting save to my database what to do??? Please suggest…

  6. Hi i have an error
    Parse error: syntax error, unexpected '{' in C:xampphtdocseasylearnUTUBEconnect.php on line "{ echo "<h3>Student's data is inserted successfully</h3>"; }"
    but the code is exactly as yours !! 🙁
    what to do???

Leave a Reply