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 ie 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.
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);
$IP = "0.0.0.0";?
Instead you should use 'localhost' or possibly 127.0.0.1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.