PHP adds MySQL data recording code_PHP tutorial

WBOY
Release: 2016-07-21 15:51:36
Original
836 people have browsed it

First create a query page:

Copy code The code is as follows:





Add record



Employee name:


PC name:







You should still remember that the technology of how to transfer values ​​​​between PHP pages has been introduced in the previous topic. Similarly, in this page, when we click submit, we will pass the two parameters ename and pcname to the add_finish.php page through the post method.

Next is the most important thing, let’s take a look at how to use PHP to write statements to add MySQL data:
Copy code The code is as follows :

$link =mysql_connect("localhost","root","admin password");
mysql_select_db("infosystem", $link);
$exec="insert into info (ename,pcname) values ​​('".$_POST["ename"]."','".$_POST["pcname"]."')";
mysql_query("SET NAMES GB2312");
mysql_query($exec, $link);
mysql_close($link);
echo "Added successfully!";
?>
The red part is the key SQL statement for adding MySQL data to PHP. Then use mysql_query to execute this SQL statement.

I would like to remind everyone that you must pay attention to any symbol in the program, because this program has been tested by me and passed normally. When copying, you only need to copy everything, but when you write it yourself Be sure to pay attention to every detail.

Another point is that everyone should make subtle modifications to the program according to their own database structure to meet everyone's specific needs.
Today’s topic is relatively simple and briefly introduces how to use PHP to add MySQL data records. I will add a more detailed introduction in a future topic.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319146.htmlTechArticleFirst create a query page: Copy the code as follows: html head /head body h3Add record/h3 formaction="add_finish .php"method="POST" Employee name: inputtype="text"size=25name="en...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!