Technology Networking & Internet

How to Insert Data With PHP in MySQL

    • 1). Create a blank text file and name it "insert.php." Open it in a plain text editor, adding an opening line reading "<?php" and a closing line reading "?>." All other lines of PHP code need to go between these two statements.

    • 2). Write a command to connect to the MySQL server on the second line using the "mysql_connect" syntax: "$link = mysql_connect(SERVER,USERNAME,PASSWORD);." Replace "server" with the location of your MySQL database and "username" and "password" with your login details. If the server was located at "mysql.example.com," and your username was "johndoe" with the password "12345," you would type:

      "$link = mysql_connect(mysql.example.com,"johndoe","12345");"

    • 3). Add a line to select the database using the $link variable. The line should read "mysql_select_db(DATABASE,$link);," where "database" is replaced by the name of the actual database. For instance, if the database was called "2011_graduates," your code would read:

      "mysql_select_db("2011_graduates",$link);."

    • 4). Create a MySQL query with the "INSERT INTO" syntax (you will need to know the name of the table and the name of the columns inside it.) If the table was called "english_students" and contained the columns "lastname," "firstname" and "gpa," the query would look like this:

      "INSERT INTO english_students (lastname, firstname, gpa) VALUES ('doe', 'john', '4.0')".

    • 5). Insert the MySQL query between the parentheses of a "mysql_query" function on a new line:

      "mysql_query("INSERT INTO english_students (lastname, firstname, gpa) VALUES ('doe', 'john', '4.0')");."

    • 6). Close the active MySQL link with a fifth line containing the code "mysql_close($link);." Save the PHP file and close the text editor.

Related posts "Technology : Networking & Internet"

We All Know What Web Hosting Is, Right?

Networking

SEO * Keep in Mind the Big Difference within Page Ratings

Networking

The NAT Configuration of the H3C Router

Networking

If I Accidentally Blocked Yahoo! Mail From My Computer, How Can I Fix It?

Networking

Simple, Straightforward Affiliate Marketing Techniques And Suggestions

Networking

How to Set Up Knology Email

Networking

Registry Enabling Tools

Networking

Reasons To Use VoIP

Networking

How to Change the Setup for Your Internet

Networking

Leave a Comment