-
-
$con = mysql_connect("localhost","peter","abc123"); - if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
- VALUES ('Peter', 'Griffin', '35')");
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
- VALUES ('Glenn', 'Quagmire', '33')");
mysql_close($con);
- ?>
-
-
Copy the code
from the form Insert data into database
Now, create an HTML form that will insert new records into the "Persons" table.
HTML form:
/** * insert into insert data * edit: bbs.it-home.org */ $con = mysql_connect("localhost","peter","abc123"); if (!$con) - {
- die('Could not connect: ' . mysql_error());
- }
mysql_select_db("my_db", $con);
$ sql="INSERT INTO Persons (FirstName, LastName, Age)
- VALUES
- ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
- < ;p>if (!mysql_query($sql,$con))
- {
- die('Error: ' . mysql_error());
- }
- echo "1 record added";
mysql_close($con)
- ?>
-
-
-
- Copy code
-
-
-
-
-
-
|