Welcome to Techno Smarter QA, Questions, Answers Community
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the Technical & Programming related questions that you want. Join our community and help others .
+1 vote
20 views

I have watched your video tutorial. I have done the same and cheacked 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 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 name engi  and table name record. 

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

in PHP by (130 points) 2

1 Answer

0 votes

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 error from your connection code because dbpass     is not correct with empty value. I think you are getting error or your server is not displaying any error . You are missing a double quotation mark. 

$dbpass = '' ";

I can check that you are using single quotes . The standard of PHP says you use 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.  Lets discuss it . I thin 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

by (7k points) 8 27 62
...