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
What is the use of stripslashes in php?
What is difference between array_merge and array_combine in php?
Which function gives us the number of affected entries by a query?
Explain what is the difference between mysql_fetch_array() and mysql_fetch_assoc()?
What does the unlink() function means?
Is empty check in php?
How do you define a constant?
How to check a key exist in an array?
How does the identity operator ===compare two values in PHP?
Is json a string php?
Does exist in php?
Explain me differences between get and post methods?
What is the apache?
How do you use an array in excel?
What are the advantages of indexes in php?