Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm getting an error when I press the submit in my form.




PHP
<?php

// php code to Insert data into mysql database from input text
if(isset($_POST['insert']))
{
    $hostname = "localhost";
    $username = "coleman";
    $password = "Kkkholiday@33";
    $databaseName = "test";
    
    // get values form input text and number

    $id = $_POST['id'];
    $name = $_POST['name'];
    $vin = $_POST['vin'];
    
    // connect to mysql database using mysqli

    $connect = mysqli_connect($localhost, $coleman, $Kkkholiday@33, $test);
    
    // mysql query to insert data

    
    
    INSERT INTO `test`(`id`, `name`, `vin`) VALUES ([id],[name],[vin])
    
    $result = mysqli_query($connect,$query);
    
    // check if mysql query successful

    if($result)
    {
        echo 'Data Inserted';
    }
    
    else{
        echo 'Data Not Inserted';
    }
    
    mysqli_free_result($result);
    mysqli_close($connect);
}

?>

<!DOCTYPE html>

<html>

    <head>

        <title> PHP INSERT DATA </title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>
        <form action="php_insert_data_in_mysql_database.php" method="post">

            <input type="text" name="id" required placeholder="id"><br><br>

            <input type="text" name="name" required placeholder="name"><br><br>

            <input type="text" name="vin" required placeholder="vin" ><br><br>

            <input type="submit" name="insert" value="Add Data To Database">

        </form>

    </body>

</html>


What I have tried:

I'm getting an error when I press the submit in my form.




PHP
<?php

// php code to Insert data into mysql database from input text
if(isset($_POST['insert']))
{
    $hostname = "localhost";
    $username = "coleman";
    $password = "Kkkholiday@33";
    $databaseName = "test";
    
    // get values form input text and number

    $id = $_POST['id'];
    $name = $_POST['name'];
    $vin = $_POST['vin'];
    
    // connect to mysql database using mysqli

    $connect = mysqli_connect($localhost, $coleman, $Kkkholiday@33, $test);
    
    // mysql query to insert data

    
    
    INSERT INTO `test`(`id`, `name`, `vin`) VALUES ([id],[name],[vin])
    
    $result = mysqli_query($connect,$query);
    
    // check if mysql query successful

    if($result)
    {
        echo 'Data Inserted';
    }
    
    else{
        echo 'Data Not Inserted';
    }
    
    mysqli_free_result($result);
    mysqli_close($connect);
}

?>

<!DOCTYPE html>

<html>

    <head>

        <title> PHP INSERT DATA </title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>
        <form action="php_insert_data_in_mysql_database.php" method="post">

            <input type="text" name="id" required placeholder="id"><br><br>

            <input type="text" name="name" required placeholder="name"><br><br>

            <input type="text" name="vin" required placeholder="vin" ><br><br>

            <input type="submit" name="insert" value="Add Data To Database">

        </form>

    </body>

</html>
Posted
Updated 30-Jul-16 21:12pm

1 solution

This I the form! When I press submit it takes me to a error page, and says,..

The requested URL /php_insert_data_in_mysql_database.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at www.kailuslist.com Port 80

*// code starts here//*
PHP
<?php

// php code to Insert data into mysql database from input text
if(isset($_POST['insert']))
{
    $hostname = "localhost";
    $username = "root";
    $password = "";
    $databaseName = "test_db";
    
    // get values form input text and number

    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $age = $_POST['age'];
    
    // connect to mysql database using mysqli

    $connect = mysqli_connect($hostname, $username, $password, $databaseName);
    
    // mysql query to insert data

    $query = "INSERT INTO `users`(`fname`, `lname`, `age`) VALUES ('$fname','$lname','$age')";
    
    $result = mysqli_query($connect,$query);
    
    // check if mysql query successful

    if($result)
    {
        echo 'Data Inserted';
    }
    
    else{
        echo 'Data Not Inserted';
    }
    
    mysqli_free_result($result);
    mysqli_close($connect);
}

?>

<!DOCTYPE html>

<html>

    <head>

        <title> PHP INSERT DATA </title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>
        <form action="php_insert_data_in_mysql_database.php" method="post">

            <input type="text" name="fname" required placeholder="First Name"><br><br>

            <input type="text" name="lname" required placeholder="Last Name"><br><br>

            <input type="number" name="age" required placeholder="Age" min="10" max="100"><br><br>

            <input type="submit" name="insert" value="Add Data To Database">

        </form>

    </body>

</html>
 
Share this answer
 
Comments
Patrice T 31-Jul-16 3:31am    
Use Improve question to update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900