dongtaotao19830418 2014-09-25 10:17
浏览 33

注册不在PHP中工作

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.

  • 写回答

2条回答 默认 最新

  • dongpu3792 2014-09-25 10:46
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭