0

我正在使用 jquery mobile 并制作一个简单的注册页面并尝试使用 ajax 提交表单

我有以下脚本

<script>
  $(document).ready(function(){
            $('#submit').click(function(){

                var formData = $("#registrationform").serialize();

                $Ajax({
                    type:"POST",
                    url:'register.php',
                    data:formData,
                    success:function(data)
                    {
                        alert('succedded')
                       $('#notification').text(data);
                    },
                    error:function(data)
                    {
                        alert('failed')
                       $('#notification').text(data); 
                    }
                });
            });
        });

请告诉我错误在哪里,通知 div 中没有显示任何内容,也没有数据保存在数据库中出了什么问题

我的 register.php 看起来像这样

$Name = $_POST[username];
   $password = $_POST[password];
   $email=$_POST[Email];
   $con=  mysql_connect('localhost','root','');
   mysql_select_db('mobileblog',$con);
   $sql="select * from users where Name like '$Name'";
   $result=  mysql_db_query($sql, $connection);
   $row=  mysql_fetch_row($result);
   if($row)
   {
       echo 'username already exist,try another name' ;
   }
   else
  {
       $sql="insert into users (Name,password,email) values('$Name','$password','$email')";
       $retval=mysql_query($sql, $connection);
       if(! $retval)
       {
           echo 'error:try later';
       }
       else 
       {

           echo 'You have been registered successfuly';
      }
  } 
4

1 回答 1

0

mysql_num_rows用于计数行并用 $con 替换 $connection

  $Name = $_POST[username];
$password = $_POST[password];
$email=$_POST[Email];
$con=  mysql_connect('localhost','root','');
mysql_select_db('mobileblog',$con);
$sql="select * from users where Name like '$Name'";
$result=  mysql_db_query($sql, $con);
$row_count =  mysql_num_rows($result);
if($row_count>0) {
    echo 'username already exist,try another name' ;
} else {

    $sql="insert into users (Name,password,email) values('$Name','$password','$email')";
    $retval=mysql_query($sql, $con);
    if(! $retval)
    {
        echo 'error:try later';
    }
    else
    {

        echo 'You have been registered successfuly';
    }
}
于 2013-10-09T11:50:36.383 回答