php - 查询不将字符串数据插入表中

标签 php mysql

我正在尝试使用 PHP 将一些数据插入 MySQL 数据库。我的代码在本地主机上运行良好,但是当我在服务器上尝试时,会插入 reg_user_id、reg_user_access_level 和 reg_user_status,而所有其他字段则不会。

请帮忙,我已经浪费了一天的时间来解决这个问题。

到目前为止一切都很好

PHP 是:

else {
    //sort the data
    $reg_user_name = mysql_real_escape_string($_POST['reg_user_name']);
    //create a salt for the password before encryption, use the same when retrieving the password!
    $salt = 'mysalt';//not actually this
    //first encryption
    $reg_user_password = sha1($_POST['reg_user_password']);
    //second encryption with salt
    $reg_user_password = sha1($salt.$reg_user_password);
    $reg_user_password = mysql_real_escape_string($reg_user_password);
    /*** strip injection chars from email ***/
    $reg_user_email = preg_replace( '((?:\n|\r|\t|%0A|%0D|%08|%09)+)i','',$_POST['reg_user_email']);
    $reg_user_email = mysql_real_escape_string($reg_user_email);

    //connect to the db
    include '../-useful_scripts/php/mysqli_connect_dsnydesign.php';

    //check the connection
    if($dbc) {

        /*** check for existing username and email ***/
        $query = "SELECT reg_user_name, reg_user_email FROM reg_users WHERE reg_user_name = '{$reg_user_name}' OR reg_user_email = '{$reg_user_email}';";
        $result = mysqli_query($dbc, $query);
        $row = mysqli_fetch_row($result);
        if (sizeof($row) > 0) {
            foreach($row as $value) {
                echo $value.'<br>';
            }
            if($row[0] == $reg_user_name) {
                $errors[] = 'Sorry, the username is already in use';
            }
            elseif($row[1] == $reg_user_email) {
                $errors[] = 'This Email address is already subscribed';
            }
            mysqli_free_result($result);
        }
        else {
            /*** create a verification code ***/
            $verification_code = uniqid();
            //set the query
            $query = "INSERT INTO reg_users(reg_user_id, reg_user_name, reg_user_password, reg_user_email, reg_user_access_level, reg_user_status) VALUES (NULL, '$reg_user_name', '$reg_user_password', '$reg_user_email', '1', '$verification_code');";
            //run the query
            if(mysqli_query($dbc, $query)) {

在此之后继续通知提交。

最佳答案

检查您在服务器和本地主机上使用的 PHP 版本号是否相同。 mysql_real_escape_string 在最新版本的 PHP 中已被弃用。

关于php - 查询不将字符串数据插入表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18163312/

相关文章:

php - 更改后不显示新数据

php - 下拉列表中的 JSON 值显示 ID 号而不是数据库中的字符串

php - MAMP Pro for multiple wordpress 安装连接错误

php - 不使用函数检测字符串结尾

php - 不带 GET 参数的请求字符串

mysql - 给出用户的总订单价格,不重复

php - 根据另一个表中的名称更新字段

php - SQL 多计数查询

mysql - 在存储过程中打印多行

mysql - 语法错误或访问冲突 - SQL 查询和 Laravel