my life would suck without you PHP adds MySQL data logging code

WBOY
Release: 2016-07-29 08:38:11
Original
1063 people have browsed it

First create a query page:

Copy the code The code is as follows:





Add record

Employee name:
< ;br>
PC name:







You should still remember that in the previous topic, we have introduced how to transfer values ​​​​between PHP pages technology. 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 write statements to add MySQL data in PHP:

Copy the code The code is as follows:

$link =mysql_connect("localhost" ,"root","Administrator 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, you must pay attention to every symbol. A detail.
Another point is that everyone should make slight 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 add MySQL data records using PHP. I will add a more detailed introduction in a future topic.

The above introduces my life would suck without you PHP to add MySQL data recording code, including the content of my life would suck without you. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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