I am new to programming and learning php. I've just created simple form with three fileds such as user name, user password, user email and submit button.
In backend, i created table which 4 fields, id - primary key, user name , pwd, email.
This is registration.php which contains html code for form.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration Form</title>
</head>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="reg.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Registration Form </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td><input name="myemail" type="text" id="myemail" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>
In form action i called reg.php. code is below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
//including dabase connection file.
include "dbc.php";
$uname = $_POST['myusername'];
$upwd = $_POST['mypassword'];
$umail = $_POST['myemail'];
$query ="INSERT INTO users (user_id, user_name, user_pwd, user_email) VALUES ('NULL', '".$uname."', '".$upwd."', '".$umail."')";
mysql_query($query) or die( 'error' );
//msql_close();
echo "Database updated";
?>
</body>
</html>
In this above code i add the file using 'include' which contains database connection dbc.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>db connection</title>
</head>
<body>
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "my_data";
//connecting database
$ms = mysql_connect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}
// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>
</body>
</html>
When i run the script in registraion.php in browser, I add all the value in fields and enter the button, it is added the value to database.
But i tried again, then its not adding anymore. what did i do wrong? Please help me!
Note: I am using XAMPP in windows7.