0

i have 2 files : - form.php :

<html>
<head>
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script>

        $(function()
        {

            $('#r').click(function()
            {
            pseudo= $("#pseudo").val();
            password= $("#password").val();

            $.ajax({
                    type:"POST",
                    url:"insert.php",
                    data:'pseudo='+pseudo+'&password='password,
                    success:function(data)
                    {
                        if(data == 1)
                        {
                            alert("ddd");
                        }
                        else
                        {
                            alert("lll");
                        }
                    }
                });
            });
        });

    </script>
</head>

<body>


        <center>
            <form class="well form-inline" method="post" action="buscarUsuario.php">
                <a class="btn btn-danger" href="" id="r">Save</a>
                <input type="text" style="height: 30px" class="span4" placeholder="Pseudo" id="pseudo" />
                <span id="error"></span>
                <span id="ok"></span>
                <input type="password" style="height: 30px" class="span4" placeholder="Password" id="password"/>
                <button type="submit" style="width: 95px" class="btn btn-primary" value="Entrar" name="Entrar">Entrar</ button>     
            </form>
        <center>

</body>
</html>

and i want to save pseudo and password in my data base through this file insert.php :

<?php

require "connecttoBD.php";

$pseudo= $_POST["pseudo"];
$password= $_POST["password"];



$sql="INSERT INTO usuarios (pseudo,password) VALUES ('$pseudo,$password') ";
$req=mysql_query($sql) or die (mysql_error());

echo "1";

?>

but when i fill out the 2 fields and press the button Save I have not saved the 2 fields in my data base. can anyone help me please ? thank you.

4

2 回答 2

2
data:'pseudo='+pseudo,

在某一方面的变化

data:{ pseudo:pseudo,
       password:password
},

在您的 ajax 请求中

于 2013-08-21T17:12:24.490 回答
0

尝试

$sql="INSERT INTO usuarios (pseudo,password) VALUES ('$pseudo','$password') ";
$req=mysql_query($sql) or die (mysql_error());

并安装了

if(data == 1)

利用

if($.trim(data) == 1)
于 2013-08-21T17:32:26.017 回答