×

Please Login or Register to continue.

3
(1.1K Views)

I have watched your video tutorial. I have done the same and checked each and every code line in PHP. Here is my PHP file code in which I have created a form to save(insert) data into the MySQL database. 

<?php

include("config.php");

?>



<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<form action="" method="POST">

<table>

<tr><td>Name</td></tr>

<tr><td><input type="text" name="name" ></td></tr>

<tr><td>Email</td></tr>

<tr><td><input type = "email" name="email"></td></tr>

<tr><td>Mobile</td></tr>

<tr><td><input type = "mobile" name="mobile"></td></tr>

<tr><td>Date</td></tr>

<tr><td><input type = "date" name="date"></td></tr>

<tr><td><input type = "submit" name="submit"></td></tr>

</table>

</form>



    <?php

    if(isset($_POST['submit']))

    {

    $name=$_POST['name'];

    $email=$_POST['email'];

    $mobile=$_POST['mobile'];

    $date=$_POST['date'];



    $result = mysqli_query($mysqli,"INSERT into record values('','$name','$email','$mobile','$date')");



    if($result)

    {

    echo "Success";

    }

    else

    {

    echo "Failed";

    }

    }

    ?>



</body>

</html>

and config.php file..

<?php
$dbhost = 'localhost';
$dbname = 'engi';
$dbusername = 'root';
$dbpass = '';
$mysqli=mysqli_connect($dbhost,$dbusername,$dbpass,$dbname);
?>

I have used the name engi and table name record. 

If I submit data by pressing a button, it gives me nothing error or data doesn't save into the MySQL database. 

 

(150 Points)
in PHP

Share

1 Answer
(7.3K Points)
(edited)
0

Data saving is another method of PHP programming in which you should have knowledge about connection file, MYSQL inserts query and HTML form then you will be able to save or insert database into the MYSQL database using PHP. I have checked your code and want to say about your query and connection. You are getting errors from your connection code because dB pass is not correct with empty value. I think you are getting errors or your server is not displaying any errors. You are missing a double quotation mark. 

$dbpass = '' ";

I can check that you are using single quotes. The standard of PHP says you use a single quotation mark. 

$dbpass = ' ';

If you want to save HTML form data into MySQL database using PHP then you should use the INSERT query. I think you have an id auto-increment. 

The same pattern is missing here.  Let's discuss it. I think you are missing a single quotation mark in your query. 

$result = mysqli_query($mysqli,"INSERT INTO record VALUES (' ','$name','$email','$mobile','$date')");

Now, check your code and make it correct and execute. 

I have other tutorials for you. 

Insert data and display in HTML table using PHP 

Insert(Signup) form in PHP 

https://technosmarter.com/qa/514/how-to-insert-html-radio-button-value-in-database-using-php-with-mysql


Comment

Related Questions :-

Your Answer

You can post your answer after login..