how to store date to database

Answer Posted / dev

for database connectivity

<?php
$con = mysql_connect("localhost","your database username
here","your database password here") or die("could
not connect".mysql_error());
$db = mysql_select_db("your database name here") or die
("could not select db".mysql_error());
?>

insert into a table

$sql_query= "insert into your table name here(table fields
name here)
values(Fields values here)";
$result = mysql_query($sql_query);
?>

FOR EXAMPLE....

<?php
//for database connectivity
$con = mysql_connect("localhost","peter","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}


mysql_select_db("my_db", $con); // select a database

$firstname=$_POST['firstname'];
$lastname = $_POST['lastname'];

// insert into a table
mysql_query("INSERT INTO Persons (FirstName, LastName)
VALUES ('$firstname','lastname ')");

mysql_close($con);
?>

<html>
<body>

<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
<input type="submit" />
</form>

</body>
</html>

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a super () and this () keywords be in same constructor?

565


What software is required to run php?

644


Why laravel is best php framework?

622


Is php good for career?

619


What the limitation of header() function in php?

580






What are the popular content management systems (cms) in php?

558


What websites use php?

609


What are the uses of implode() function?

664


What is default session time in php?

590


How can we submit form without a submit button?

630


what does this symbol mean in php?

745


How is csrf token generated?

601


What is difference between action hook and filter hook?

569


How can I convert ereg expressions to preg in php?

566


Who is the father of php?

656