douxie9347 2017-06-16 22:13
浏览 15
已采纳

托管到网站时出现Mysqli错误

I'm having a very strange issue here. I have this code here which is 100% functioning on my localhost but when I host it to godaddy the insert command doesn't function while the select command functions. Code below

Register.php

 <!DOCTYPE html>
<html>
<head>
    <title>Doc Title</title>
</head>

<body class="signup-page" style="background-color:#f5cf00;">
    <div class="signup-box">
         <div class="logo">
            <h1>

            <?php 
                ob_start();
                include 'includes/connect.php';
                $error = false;
                if ( isset($_POST['sign_up']) ) 
                    {
                        // clean user inputs to prevent sql injections
                        $user_name = trim($_POST['user_name']);
                        $user_name = strip_tags($user_name);
                        $user_name = htmlspecialchars($user_name);

                        $gender = trim($_POST['gender']);
                        $gender = strip_tags($gender);
                        $gender = htmlspecialchars($gender);

                        $dob = trim($_POST['dob']);
                        $dob = strip_tags($dob);
                        $dob = htmlspecialchars($dob);

                        $email = trim($_POST['email']);
                        $email = strip_tags($email);
                        $email = htmlspecialchars($email);

                        $country = trim($_POST['country']);
                        $country = strip_tags($country);
                        $country = htmlspecialchars($country);

                        $phone = trim($_POST['phone']);
                        $phone = strip_tags($phone);
                        $phone = htmlspecialchars($phone);

                        $username = trim($_POST['username']);
                        $username = strip_tags($username);
                        $username = htmlspecialchars($username);

                        $password = trim($_POST['password']);
                        $password = strip_tags($password);
                        $password = htmlspecialchars($password);

                        // if there's no error, continue to signup
                        if( !$error ) {
                                        $query = "INSERT INTO users
                                        (user_role,user_name,gender,dob,email,country,phone,username,password,added_by,  added_date) 
                                        VALUES
                                        ('User','$user_name','$gender','$dob','$email','$country','$phone','$username', '$password','Register Page',now())";
                                        $res = mysqli_query($con,$query);
                                        if ($res) 
                                                {
                                                    $errTyp = "success";
                                                    $errMSG = "Registration Successful, You can now login.";
                                                    echo $errMSG;
                                                } 
                                        else 
                                            {
                                                $errTyp = "danger";
                                                $errMSG = "Something went wrong, try again later..."; 
                                            } 
                                        }
                                }
                            ?>
                        </h1>
                    </div>

                    <div class="card">
                        <div class="body">
                            <form id="sign_up"  action="register.php" method="POST">
                    <div class="msg">Register a new membership</div>
                    <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">person</i>
                        </span>
                        <div class="form-line">
                            <input type="text" class="form-control" name="user_name" placeholder="Full Name" required autofocus>
                        </div>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">group</i>
                        </span>
                        <div class="form-line">
                           <select name="gender" class="form-control show-tick">
                                        <option value="">-- Select Gender --</option>
                                        <option value="Male">Male</option>
                                        <option value="Female">Female</option>
                            </select>
                        </div>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">date_range</i>
                        </span>
                        <div class="form-line">
                            <input name="dob" type="date" class="form-control" placeholder="Please choose a date...">
                        </div>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">email</i>
                        </span>
                        <div class="form-line">
                            <input type="text" class="form-control" name="email" placeholder="Email" required autofocus>
                        </div>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">my_location</i>
                        </span>
                        <div class="form-line">
                            <select name="country" class="form-control show-tick">
                                        <option value="">-- Select Country --</option>
                                        <option value="country_1">country 1</option>
                                         <option value="country_2">country 2</option>
                            </select>
                        </div>
                    </div>

                     <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">phone</i>
                        </span>
                        <div class="form-line">
                            <input name="phone" type="text" class="form-control" name="namesurname" placeholder="number" required autofocus>
                        </div>
                    </div>
                     <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">person</i>
                        </span>
                        <div class="form-line">
                            <input name="username" type="text" class="form-control" name="namesurname" placeholder="Username" required autofocus>
                        </div>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">
                            <i class="material-icons">lock</i>
                        </span>
                        <div class="form-line">
                            <input name="password" type="password" class="form-control" name="namesurname" placeholder="Password" required autofocus>
                        </div>
                    </div>


                    <button name="sign_up" class="btn btn-block btn-lg bg-pink waves-effect" type="submit">SIGN UP</button>

                    <div class="m-t-25 m-b--5 align-center">
                        <a href="login.php">You already have a membership?</a>
                    </div>
                </form>
            </div>
        </div>
    </div>


</body>

</html>

Database:

CREATE TABLE `users` (
  `user_id` int(11) NOT NULL,
  `user_role` varchar(255) NOT NULL,
  `user_name` varchar(255) NOT NULL,
  `gender` varchar(255) NOT NULL,
  `dob` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `country` varchar(255) NOT NULL,
  `city` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `added_by` varchar(255) NOT NULL,
  `added_date` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I hope my question was clear and any help or support identifying the problem is appreciated.

EDIT: My connect.php file when uploaded

<?php
$con = mysqli_connect('localhost','user here','pass here');
if (empty($con)) {
    echo mysqli_error();
 } 
 $data = mysqli_select_db($con,"dbname here");
 if (empty($data)) {
    echo mysqli_error();
 }
?>
  • 写回答

1条回答 默认 最新

  • duanqian2278 2017-06-16 22:25
    关注

    Issue fixed.. I realized the problem was not my code it is the database engine.. Due to my lack of understanding of phpmyadmin I was running an outdated version and on godaddy they run an up to date version so when I recreated the database tables on godaddy everything worked out fine.

    Edit and the field type on my localhost were Innodb while the godaddy is going for MYISAM.. Rookie mistake :D

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。