টেক্সট বক্স থেকে ডাটা ইনসার্ট করা
টেক্সট বক্স থেকে ডাটা ইনসার্ট করতে, নিচের HTML কোড দিয়ে টেক্সট বক্স বানিয়ে নিতে হবে এবং insert2.php নামে একটি ফাইল বানাতে হবে । submit বাটনে ক্লিক করার সাথে সাথে টেক্সট বক্সের ডাটা insert2.php এ প্রেরিত হবে এবং ডটাবেজে ইনসার্ট হবে।
insert-form.php ফাইল তৈরী করতে হলে, নিচের নিয়ম মেনে চলি,
প্রথম লাইনে, <html> কোড লিখি, পরের লাইনে <body> লিখি,
পরের লাইনে লিখি <form action=”insert2.php” method=”post”>
পরের লাইনে লিখি,
Firstname: <input type=”text” name=”firstname” />
পরের লাইনে লিখি,
Lastname: <input type=”text” name=”lastname” />
পরের লাইনে লিখি,
Age: <input type=”text” name=”age” />
পরের লাইনে লিখি,
<input type=”submit” />
পরের লাইনে লিখি,
</form>
পরের লাইনে লিখি,
</body>
পরের লাইনে লিখি
</html>
এখন insert2.php ফাইল তৈরী করব নিচের কোড দিয়ে, যেমন
প্রথম লাইনে লিখি, <?php , পরের লাইনে লিখি,
$con = mysql_connect(“localhost”,” hedaetul_bd”,”password”);
পরের লাইনে লিখি,
if (!$con)
পরের লাইনে লিখি,
{
পরের লাইনে লিখি,
die(‘Could not connect: ‘ . mysql_error());
পরের লাইনে লিখি,
}
পরের লাইনে লিখি,
mysql_select_db(“hedaetul_bd”, $con);
পরের লাইনে লিখি,
$sql=”INSERT INTO Persons (FirstName, LastName, Age) VALUES
(‘$_POST[firstname]‘,’$_POST[lastname]‘,’$_POST[age]‘)”;
পরের লাইনে লিখি,
if (!mysql_query($sql,$con))
পরের লাইনে লিখি,
{
পরের লাইনে লিখি,
die(‘Error: ‘ . mysql_error());
পরের লাইনে লিখি,
}
পরের লাইনে লিখি,
echo “1 record added”;
পরের লাইনে লিখি,
mysql_close($con)
পরের লাইনে লিখি,
?>
Inserting data from the text box
To insert data from a text box, the text box with the following HTML code to be made and will make a file called insert2.php. In addition to the text box and click submit the data to be transmitted at insert2.php and databeje to insert.
insert-form.php To create a file, follow the rules below,
The first line, <html> code to write the next line in the <body> write,
Write the next line <form action = "insert2.php" method = "post">
Write the next line,
Firstname: <input type = "text" name = "firstname" />
Write the next line,
Lastname: <input type = "text" name = "lastname" />
Write the next line,
Age: <input type = "text" name = "age" />
Write the next line,
<Input type = "submit" />
Write the next line,
</ Form>
Write the next line,
</ Body>
Write the next line
</ Html>
Insert2.php will now create a file with the following code, for example
Write the first line, <? Php, write the next line,
$ Con = mysql_connect ( "localhost", "hedaetul_bd", "password");
Write the next line,
if (! $ con)
Write the next line,
{
Write the next line,
die ( 'Could not connect:'. mysql_error ());
Write the next line,
}
Write the next line,
mysql_select_db ( "hedaetul_bd", $ con);
Write the next line,
$ Sql = "INSERT INTO Persons (FirstName, LastName, Age) VALUES
( '$ _POST [Firstname]', '$ _ POST [lastname]', '$ _ POST [age]') ";
Write the next line,
if (! mysql_query ($ sql, $ con))
Write the next line,
{
Write the next line,
die ( 'Error:'. mysql_error ());
Write the next line,
}
Write the next line,
echo "1 record added";
Write the next line,
mysql_close ($ con)
Write the next line,
?>