Friday, February 23, 2007

How to add data in Mysql From Php

Adding information in the database (a mysql database) using PHP is not a hard thing at all...
You just use a function:

mysql_query(" ");
between " " you must add the mysql command that adds the information.
for example: you have a table named "user" that contains:
user name
How do you add information to mysql from the page you have?


Let's say you have the information stored in the variables:
$user_name and $password
you just use the following command:

mysql_query("INSERT INTO `user` (`user_name`, `password) VALUES ('$user_name', '$password')");
user is the name of the table
you must put tables and rows and everything that is not a value in ``
you put values in ''
` is a character on the left of the 1 button on your keyboard !
' is the second one on the right of L button on your keybord
values are variables themselves!!!
you can also write the insertion like this:
mysql_query("INSERT INTO `user` (`user_name`, `password) VALUES ('".$user_name."', '".$password."')");
in order to make the variables $user_name and $password outside of the mysql_query function.

1 comment:

Anonymous said...

Thank you, I've been trying to get a flex front end to post to mySQL and I have been looking around for a couple days off and on and this post is what finally got it working, Thanks again, Edwin