I am trying to create a simple login program but the data is not going to phpMyAdmin.
I am using wamp server for phpmyadmin & have database named 'firstdatabase' and table named 'reg'.
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<h1 align="center">Registration</h1>
<form action="" method="get">
<table width="261" border="1" align="center">
<tr>
<td width="85">ID : </td>
<td width="160"><label>
<input name="id" type="text" id="id" />
</label></td>
</tr>
<tr>
<td>Password :</td>
<td><label>
<input name="pass" type="password" id="pass" />
</label></td>
</tr>
<tr>
<td>Email ID : </td>
<td><label>
<input name="email" type="text" id="email" />
</label></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit" />
</div></td>
</tr>
</table>
<label></label>
</form>
</body>
</html>
<?php
if ( $_POST )
{
$con=mysqli_connect('localhost','root','','firstdatabase');
if (!$con)
{
echo"Connected to server...";
}
$id=$_POST['user_id'];
$pass=$_POST['user_name'];
$email=$_POST['user_email'];
$query = "
INSERT INTO `firstdatabase`.`reg` (`user_id`, `user_pass`, 'user_email') VALUES ('$id', '$pass', '$email')";
mysql_query($query);
echo "<h2>Thank you for your registering!</h2>";
mysql_close($con);
}
?>
You are fetching the wrong fields, the ones you are fetching don't exist:
$id=$_POST['id'];
$pass=$_POST['pass'];
$email=$_POST['email'];
And you are connecting with mysqli and then are trying to run a mysql query, this won't work either.
Change this line:
mysql_query($query);
to
mysqli_query($con,$query);
Your insert query contains an error, too:
INSERT INTO `firstdatabase`.`reg` (`user_id`, `user_pass`, 'user_email') // < 'user_email'
should be
INSERT INTO `firstdatabase`.`reg` (`user_id`, `user_pass`, `user_email`) // backticks
As a sidenote, as it doesn't interrupt your program but still is wrong
$con=mysqli_connect('localhost','root','','firstdatabase');
if (!$con)
{
echo"Connected to server...";
}
Doesn't make sense. The !
in front of your $con
variable will check for is not
SIDENOTE 2:
enable error reporting, all the errors you are asking for will then be displayed:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
and enable error reporting for your query!