0

hi i am trying to create a registration page using html and php and the database is mysql. the IDE i am using is cloud9. the code for my form is as follows:

<form action="signup_code.php" method="post">
                        <p>Name<br/><input type="text" name="name" maxlength="20"  ></p>
                        <p>Phone Number<br/><input type="number" name="phone" maxlength="20"  ></p>
                        <p>Email<br/><input type="email" name="email" maxlength="50" ></p>
                        <p>Password<br/><input type="password" name="pass1" maxlength="20" ></p>
                        <p>Confirm Password<br/><input type="password" name="pass2" maxlength="20" ></p>
                        <p>Address<br/><input type="text" name="address" maxlength="20"  ></p>


                            <button type="submit" class="btn btn-default">Signup

                                </button>
                        </form>

the code in the signup_code .php is :

<?php
$IP = "0.0.0.0";
$dbuser = "bhaskey";

$conn = mysqli_connect($IP, $dbuser, "","trydb");
if(! $conn )
{
  die('Could not connect: ' . mysqli_error());
}

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$address = $_POST['address'];


$query = "SELECT email FROM user_main where email='".$email."'";
$result = mysqli_query($conn,$query);
$numResults = mysqli_num_rows($result);

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) // Validate email address
        {
            $message =  "Invalid email address please type a valid email!!";
        }
        elseif($numResults>=1)
        {
            $message = $email." Email already exist!!";
        }


else
        {
            mysqli_query("(insert into user_main(name,phone, email,pass1, pass2, address) values
            ('".$name."','".$phone."', '".$email."', '".pass1."','",$pass2."','".$address."')");


            echo $message = "Signup Sucessfully!!";
        }
mysqli_close($conn);
?>

however when i am executing the the code i.e clicking the signup button in the form, it is giving me the following result "Cannot POST /bhaskey/eshopper/signup_code.php"

where i am going wrong. i am sure it must be a silly mistake. but since i am pretty new and still in learning phase, it is becoming troublesome for me.

EDIT: i tried to pass the whole path of the .php file to the action in form. but after i click on the submit button, the page turns whte and nothing is displayed anymore. i tried clearing browser cache but its not helping.

ritika
  • 61
  • 1
  • 10
  • You should always use mysqli_. Your $conn should be: `$conn = mysqli_connect($IP, $dbuser, null, "trydb") or die('Could not connect: '. mysql_error());` – YvesHendseth Sep 25 '14 at 10:34
  • yes, that was a negligence on my part. but the code is still not working its is giving the same error "Cannot POST /bhaskey/eshopper/signup_code.php" – ritika Sep 25 '14 at 10:39

2 Answers2

0

You have to replace your this code

$conn = mysql_connect($IP, $dbuser, "","trydb");  

to this code

$conn = new mysqli($IP, $dbuser, "","trydb");

and also replace this code

mysql_close($conn);

to this code

mysqli_close($conn);
shashank
  • 566
  • 3
  • 10
  • 31
  • Now are you again getting same error after placing above correction.? Please let me know. It is working on my side – shashank Sep 25 '14 at 11:07
  • yes, i have made the changes you suggested...its showing the same error..:( Cannot POST /bhaskey/eshopper/signup_code.php – ritika Sep 25 '14 at 12:42
0

$IP = "0.0.0.0";?

Instead you should use 'localhost' or possibly 127.0.0.1.

Ganesh Salunkhe
  • 596
  • 1
  • 4
  • 18