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

时间:2022-06-12 16:27:44

I am trying to insert some data into a MySQL database using PHP. The code I have works fine on localhost, but when I try it on my server the reg_user_id, reg_user_access_level and reg_user_status are inserted while all the other fields are not.

我试图使用PHP将一些数据插入MySQL数据库。我在localhost上运行的代码很好,但是当我在我的服务器上尝试它时,会插入reg_user_id,reg_user_access_level和reg_user_status,而所有其他字段都没有。

Please help, I've already wasted a day trying to sort this out.

请帮助,我已经浪费了一天试图解决这个问题。

everything up to here is fine

到目前为止的一切都很好

The PHP is:

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)) {

just goes on to notify of submission after this.

在此之后继续通知提交。

1 个解决方案

#1


0  

Check that you are using the same PHP version number on your server and your localhost. mysql_real_escape_string has been deprecated in the latest version of PHP.

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

#1


0  

Check that you are using the same PHP version number on your server and your localhost. mysql_real_escape_string has been deprecated in the latest version of PHP.

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