-2

i have added action value Registration file

  <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" name="registerNew" type="submit">Register</button>
         </p>
    </fieldset>

 </form>
</div>
<body>

I have not posted all code of registration.html as it is working fine

connect.php

<?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";

$name ='';
$password ='';
if(isset($_POST['registerNew'])){
// 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!';

?> 

but still its not working and when i press register button it shows php code of connect.php

user2290749
  • 53
  • 1
  • 3
  • 7
  • 5
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Apr 17 '13 at 12:54
  • 1
    Change your form's `action` attribute to point to your PHP file, otherwise it will just be posting back to itself. – James Donnelly Apr 17 '13 at 12:54
  • Hint: What do you think the action attribute in the form tag does? – meouw Apr 17 '13 at 12:55

6 Answers6

6

Your form doesn't know where to send its data to:

<form id="RegisterUserForm" action="" method="post">

should be

<form id="RegisterUserForm" action="connect.php" method="post">
Borniet
  • 3,544
  • 4
  • 24
  • 33
  • ok i changed it but it still not working $name =''; $password =''; if(isset($_POST['registerNew'])){ // Storing form values into PHP variables $name = $_POST['name']; // Since method=”post” in the form $password = $_POST['password']; } I CHANGED php file like this – user2290749 Apr 17 '13 at 14:08
1

If on clicking the Register button , php code appears on the page , then most probably it has nothing to do with your code. Please check if you are directly double-clicking the html file for your testing . Please execute it by entering the localhost page address in the browser instead.

Eg : http://localhost/registration.html

Now the HTML should be able to execute the PHP code.

-ShazzDecoder

0

You have to add connect.php as your action attribute value in your form :

<form id="RegisterUserForm" action="connect.php" method="post">
ibi0tux
  • 2,481
  • 4
  • 28
  • 49
  • ok i changed it but it still not working $name =''; $password =''; if(isset($_POST['registerNew'])){ // Storing form values into PHP variables $name = $_POST['name']; // Since method=”post” in the form $password = $_POST['password']; } I CHANGED php file like this – user2290749 Apr 17 '13 at 14:07
  • What's happening now ? Can you please edit your original post for better readability ? By the way, your inputs are not safe. Anyone can execute SQL code through your form. – ibi0tux Apr 17 '13 at 14:20
  • "when i press register button it shows php code of connect.php" : make sure you are running your pages from a server running php – ibi0tux Apr 18 '13 at 10:44
0

With action="" in your form, nothing gets submitted. You need to tell it to call the connect.php

Floris
  • 45,857
  • 6
  • 70
  • 122
0

if you use the same page as action , you should copy the code in action.php on the page that contains form , or replace action="" with action="connect.php"

Charaf JRA
  • 8,249
  • 1
  • 34
  • 44
0

If on clicking the Register button , php code appears on the page , then most probably it has nothing to do with your code. Please check if you are directly double-clicking the html file for your testing . Please execute it by entering the localhost page address in the browser instead.

Eg : http://localhost/registration.html

Now the HTML should be able to execute the PHP code. And your folder containing html and php file should be in XAMPP->htdocs.