0

Ok my registration form data is not getting stored in database. Whereas if i do $name="Bill"; then its storing but $name='name'; is not working. Secondly when i click on register button its shows php code of file connect.php.

Registration code

<body>

<div id="registration">
 <h2><b><i>Electronic Montessori Learning</i><b></h2>

 <form id="RegisterUserForm" action="connect.php" method="post">
    <fieldset>
         <p>
            <label for="name">Name</label>
            <input id="name" name="name" type="text" class="text" value="" />
         </p>
        <p>
            <label for="password">Password</label>
            <input id="password" name="password" class="text" type="password" />
         </p>
       <p>
            <button id="registerNew" type="submit">Register</button>
         </p>
    </fieldset>

 </form>
</div>
<body>

and now connect.php code

<?php


$db=mysql_connect("localhost", "root", "") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("users") or die(mysql_error());
echo "Connected to Database";


if(isset($_POST['Submit'])){
// Storing form values into PHP variables
$name = $_POST['name']; // Since method=”post” in the form
$password = $_POST['password'];
mysql_query("INSERT INTO user_eml(Name, Password) VALUES('$name', '$password' ) ") 
or die(mysql_error());  
echo "Data Inserted!";

echo    'Thank you for submitting your details!';
}




?> 
Bhavin Rana
  • 1,554
  • 4
  • 20
  • 40
user2290749
  • 53
  • 1
  • 3
  • 7
  • Then your server is not configured with PHP. – Edwin Alex Apr 18 '13 at 10:18
  • 1
    **Careful!** The `mysql_*` functions are [old and should not be used anymore](http://bit.ly/phpmsql). Please have a look at [PDO](http://php.net/pdo) or [MySQLi](http://php.net/msqli), which are better [MySQL API choices](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Till Helge Apr 18 '13 at 10:19
  • 1
    `mysql_*` is deprecated code. please use `PDO` or `mysqli_*`. – christopher Apr 18 '13 at 10:19
  • 1
    You just have got the typical case of SQL injection. Also typically this happens while you start to use mysql with the mysql_* functions. Whoever guided you there, stop now and take a better tutorial. - Your problems are already part of your earlier questioon BTW: [Unable to connect php and html file](http://stackoverflow.com/questions/16060553/unable-to-connect-php-and-html-file) – hakre Apr 18 '13 at 10:20

2 Answers2

5

you forgot name attribute here

<button id="registerNew" type="submit" name="Submit">Register</button>

and because of that this condition will never true

if(isset($_POST['Submit']))
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
0

Your

  if(isset($_POST['Submit'])){

is wrong as in the form there is no element with name="Submit".

It means your button should have a name = "Submit".

chandresh_cool
  • 11,753
  • 3
  • 30
  • 45