Php mysql中的连接

Php mysql中的连接,php,mysql,mysqli,Php,Mysql,Mysqli,我正在做一份登记表。如果你能给我一些提示,如果我的代码是错误的或不正确的 它还在给我看这个 (插入美元)$user=$\u POST['user']$通过=$_POST['pass']$email=$_POST['email']$lname=$_POST['lname']$fname=$_POST['fname']$stmt->bind_参数($user、$pass、$email、$lname、$fname)$stmt->execute()$rowcount=$stmt->受影响的行;if($r

我正在做一份登记表。如果你能给我一些提示,如果我的代码是错误的或不正确的

它还在给我看这个 (插入美元)$user=$\u POST['user']$通过=$_POST['pass']$email=$_POST['email']$lname=$_POST['lname']$fname=$_POST['fname']$stmt->bind_参数($user、$pass、$email、$lname、$fname)$stmt->execute()$rowcount=$stmt->受影响的行;if($rowcount>0){echo“Success!”;}else{echo“Error!”;}//CLOSE执行$stmt->CLOSE();?>

这是我的密码:

    <?php
    $mysqli = new mysqli('local','root','','dbtform');
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    $sqlinsert = "INSERT INTO tblform (user, pass, email, lname, fname) 
    VALUES ('sssss',?,?,?,?,?)";
    $stmt = $mysqli->prepare($sqlinsert);

    $user = $_POST['user'];
    $pass = $_POST['pass'];
    $email = $_POST['email'];
    $lname = $_POST['lname'];
    $fname = $_POST['fname'];



    $stmt->bind_param($user, $pass, $email, $lname, $fname);
    $stmt->execute();

    $rowcount = $stmt->affected_rows;


    if ($rowcount > 0)
{
echo "Success!";
}

else
{
echo "Error!";
}

//CLOSE EXECUTE
$stmt->close();

?>


    <head>
        <title>Animated Form Switching with jQuery</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="description" content="Expand, contract, animate forms with jQuery wihtout leaving the page" />
        <meta name="keywords" content="expand, form, css3, jquery, animate, width, height, adapt, unobtrusive javascript"/>
        <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"/>
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <script src="js/cufon-yui.js" type="text/javascript"></script>
        <script src="js/ChunkFive_400.font.js" type="text/javascript"></script>
        <script type="text/javascript">
            Cufon.replace('h1',{ textShadow: '1px 1px #fff'});
            Cufon.replace('h2',{ textShadow: '1px 1px #fff'});
            Cufon.replace('h3',{ textShadow: '1px 1px #000'});
            Cufon.replace('.back');
        </script>
    </head>
    <body>
        <div class="wrapper">
            <h1>Rythreion</h1>
            <h2>Demo: click the <span>orange links</span> to see the form animating and switching</h2>
            <div class="content">
                <div id="form_wrapper" class="form_wrapper">
                    <form class="register">
                        <h3>Register</h3>
                        <div class="column">
                            <div>
                                <label>First Name:</label>
                                <input type="text" name="fname" />
                                <span class="error">This is an error</span>
                            </div>
                            <div>
                                <label>Last Name:</label>
                                <input type="text" name="lname"/>
                                <span class="error">This is an error</span>
                            </div>

                        </div>
                        <div class="column">
                            <div>
                                <label>Username:</label>
                                <input type="text" name="user"/>
                                <span class="error">This is an error</span>
                            </div>
                            <div>
                                <label>Email:</label>
                                <input type="text"  name="email"/>
                                <span class="error">This is an error</span>
                            </div>
                            <div>
                                <label>Password:</label>
                                <input type="password" name="pass" />
                                <span class="error">This is an error</span>
                            </div>
                        </div>
                        <div class="bottom">
                            <div class="remember">
                                <input type="checkbox" />
                                <span>Send me updates</span>
                            </div>
                            <input type="submit" value="Register" />
                            <a href="index.html" rel="login" class="linkform">You have an account already? Log in here</a>
                            <div class="clear"></div>
                        </div>
                    </form>
                    <form class="login active">
                        <h3>Login</h3>
                        <div>
                            <label>Username:</label>
                            <input type="text" name="user" />
                            <span class="error">This is an error</span>
                        </div>
                        <div>
                            <label>Password: <a href="forgot_password.html" rel="forgot_password" class="forgot linkform">Forgot your password?</a></label>
                            <input type="password" name="pass" />
                            <span class="error">This is an error</span>
                        </div>
                        <div class="bottom">
                            <div class="remember"><input type="checkbox" /><span>Keep me logged in</span></div>
                            <input type="submit" value="Login"></input>
                            <a href="register.html" rel="register" class="linkform">You don't have an account yet? Register here</a>
                            <div class="clear"></div>
                        </div>
                    </form>
                    <form class="forgot_password">
                        <h3>Forgot Password</h3>
                        <div>
                            <label>Email:</label>
                            <input type="text" name="email" />
                            <span class="error">This is an error</span>
                        </div>
                        <div class="bottom">
                            <input type="submit" value="Send reminder"></input>
                            <a href="index.html" rel="login" class="linkform">Suddenly remebered? Log in here</a>
                            <a href="register.html" rel="register" class="linkform">You don't have an account? Register here</a>
                            <div class="clear"></div>
                        </div>
                    </form>
                </div>
                <div class="clear"></div>
            </div>
            <a class="back" href="http://google.com">back to the Codrops tutorial</a>
        </div>


        <!-- The JavaScript -->
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(function() {
                    //the form wrapper (includes all forms)
                var $form_wrapper   = $('#form_wrapper'),
                    //the current form is the one with class active
                    $currentForm    = $form_wrapper.children('form.active'),
                    //the change form links
                    $linkform       = $form_wrapper.find('.linkform');

                //get width and height of each form and store them for later                        
                $form_wrapper.children('form').each(function(i){
                    var $theForm    = $(this);
                    //solve the inline display none problem when using fadeIn fadeOut
                    if(!$theForm.hasClass('active'))
                        $theForm.hide();
                    $theForm.data({
                        width   : $theForm.width(),
                        height  : $theForm.height()
                    });
                });

                //set width and height of wrapper (same of current form)
                setWrapperWidth();

                /*
                clicking a link (change form event) in the form
                makes the current form hide.
                The wrapper animates its width and height to the 
                width and height of the new current form.
                After the animation, the new form is shown
                */
                $linkform.bind('click',function(e){
                    var $link   = $(this);
                    var target  = $link.attr('rel');
                    $currentForm.fadeOut(400,function(){
                        //remove class active from current form
                        $currentForm.removeClass('active');
                        //new current form
                        $currentForm= $form_wrapper.children('form.'+target);
                        //animate the wrapper
                        $form_wrapper.stop()
                                     .animate({
                                        width   : $currentForm.data('width') + 'px',
                                        height  : $currentForm.data('height') + 'px'
                                     },500,function(){
                                        //new form gets class active
                                        $currentForm.addClass('active');
                                        //show the new form
                                        $currentForm.fadeIn(400);
                                     });
                    });
                    e.preventDefault();
                });

                function setWrapperWidth(){
                    $form_wrapper.css({
                        width   : $currentForm.data('width') + 'px',
                        height  : $currentForm.data('height') + 'px'
                    });
                }

                /*
                for the demo we disabled the submit buttons
                if you submit the form, you need to check the 
                which form was submited, and give the class active 
                to the form you want to show
                */
                $form_wrapper.find('input[type="submit"]')
                             .click(function(e){
                                e.preventDefault();
                             });    
            });
        </script>
    </body>
</html>

如果你能给我一些提示,如果我的代码是错误的或不正确的

当然可以。
您的代码既错误又不正确,因为它正在使用mysqli。
您必须改用PDO

只是给你一个想法的草图:
首先,创建一个连接

$dsn  = 'mysql:dbname=test;host=localhost;charset=utf8';
$opt  = array(
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn, $user, $pass, $opt);
然后,运行查询

$sql = "INSERT INTO tblform (user, pass, email, lname, fname) VALUES (?,?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute($_POST); // you may wish to unset non-used fields from POST first
if ($stmt->rowCount())
{
    echo "Success!";
}

您收到了什么错误消息?您的报价在
$sqlinsert
@ChrisCooney周围被弄乱了,它一直显示prepare($sqlinsert)$user=$\u POST['user']$通过=$_POST['pass']$email=$_POST['email']$lname=$_POST['lname']$fname=$_POST['fname']$stmt->bind_参数($user、$pass、$email、$lname、$fname)$stmt->execute()$rowcount=$stmt->受影响的行;if($rowcount>0){echo“Success!”;}else{echo“Error!”;}//CLOSE执行$stmt->CLOSE();?>@user211371注释不太适合大型代码片段。把它直接包含在问题中。@henrik我已经包含了它。