-4

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);
}

?>
Francisco C
  • 8,871
  • 4
  • 31
  • 41
Raj Thakkar
  • 77
  • 10
  • 1
    First step you need to do is to enable error reporting and logging. Then set the error level to the highest level and get your code warning and notices free: http://stackoverflow.com/q/3531703/367456 - Then there is even another website to go to first: http://bobby-tables.com/ – hakre Dec 23 '14 at 18:49
  • Your check (`if(!$con)`) is senseless. It prints out the opposite and still continues execution. – Tobias Dec 23 '14 at 18:49
  • 1
    Wamp server doesn't support `mysql_` functions, *strangely enough*. There's your answer. Plus, you're mixing MySQL APIs on top of that; which they do not mix together. Use `mysqli_` exclusively. Plus, the quotes in and for your column `'user_email'` remove them or use ticks `\`` – Funk Forty Niner Dec 23 '14 at 18:58

1 Answers1

2

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!

baao
  • 62,535
  • 14
  • 113
  • 168
  • 1
    With error reporting and logging enabled to the highest level, all those aren't any first-hand issues. PHP would have talked about these already. So the problem are not these little mistakes, the problem is to not do error logging and reporting. – hakre Dec 23 '14 at 18:49
  • That's absolutely true @hakre – baao Dec 23 '14 at 18:51