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

How to access a specific character in a string using php?

513


What are the rules for naming a php variable?

543


What do you use php for?

530


Explain what is the main difference between require() and require_once()?

535


What is the latest version of php?

531






Can constructor be private in php?

532


Can php run on windows server?

520


What is php in full?

502


What is the purpose of basename() function in PHP?

600


What is difference Between PHP 5 and 7?

512


Php says that an array is an ordered map. But how the values are ordered in an array?

593


What is php simple definition?

534


What is difference between php and html?

488


How does php strcmp work?

502


What is the use of super-global arrays in php?

503