Hello,
i have a PHP form that is supposed to get a username, password and e-mail. Once the user enters the data, how can i add it to a database?
Thank you!Code:$name = $_POST['name']; $pass = $_POST['password']; $email = $_POST['email'];
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
- connect to database server
- select database
- if you already have database and table, insert it using mysql
If you find a problem, we will discuss it then
Well it's the code i asked for, cause i know how it is supposed to work.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
What database server that you use?
Do you already have a database and create table to store the information?
Code:$username = "your_username";
$password = "your_database_password";
$host = "localhost";
$database = "name_of_database_you_using";
$connection = @mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
$db = @mysql_select_db($database) or die("Can not select the database: ".mysql_error());
Do what Hardinera showed you to connect than to add the data to the tabel
Note: Replace table with your table name
Note: the first set were it says (name, pass, email) change to the name of the fileds in your DB.
Note: Whatever order you put the fileds in is the order you must use for the values
Code:
$query = "Insert into table (name, pass,email) Values ('$_REQUEST[name]', '$_REQUEST[pass]','$_REQUEST[email]')";
$runQuery = mysql_query($query)or die("ERROR:<br /><br />" . mysql_error());
Before you put those inputted values into that query and run it, you should sanitize them first.
Code:$name = mysql_real_escape_string($_POST['name']);
$pass = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
Thanks guys, i solved it!
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks