adspace


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

Tell me what kind of things have you done on the social side?

1065


What is the difference between htmlentities() and htmlspecialchars()?

1091


What sized websites have you worked on in the past?

1086


sort term descripttion form, report and uery

2254


if you run the app program all vendor open items are cleared but is it possible to reverse the again again open items please tell me the answer

1989


What is the current stable version of php?

1124


What does $_files means?

1162


how to detect a mobile device using php

1174


Name and explain five of the PHP error constants?

1035


Write a program using while loop?

1118


How to calculate the difference between two dates using php?

1144


How to create a web form?

1111


Explain me is it possible to destroy a cookie?

1029


What is difference between static and final in php?

1109


List some features of php that are deprecated in php7?

1024