0

I switched to php 7 and this doesn't work anymore! Please help!

When I switch back to php 5.6 it suddenly works. No idea why php would affect jquery. Please help!

I have tried everything but all other code is the same, I have changed nothing. All I did was switch php versions. I am perplexed and confused. Please help!

I can even show you screenshots of my server. I changed nothing except switch php versions. Is something missing in the config?

Please help!

function fillForm(id) {
        console.log('fillForm ' + "<?=$read_call?>&id="+id+"");

        $.getJSON("<?=$read_call?>&id="+id+"", function( data ) {
        
        console.log('fillForm '+data);
        
        $.each( data, function( key, val ) {
            if(data.hasOwnProperty(key))
                    $('input[name='+key+']').val(val);

            if(key == 'acct') {                 
                    $('select[name="acct"]').find('option:contains("'+val+'")').attr("selected",true);  
            }
            
            if(key == 'priority') {                 
                    $('select[name="priority"]').find('option:contains("'+val+'")').attr("selected",true);  
                    console.log('priority '+val);
            }
            
            if(key =='extra') {
                $('textarea[name='+key+']').val(val);
            }
            
            if(key == 'password') {
                $('#passwordRow').prop('title', val);
            }
            
            if(key == 'code') {
                $('#codeRow').prop('title', val);
            }
            
            if(key == 'url') {
                $('#url_1_href').prop('href', val);
            }
            
            if(key == 'referralURL') {
                $('#url_2_href').prop('href', val);
            }
            });
        });
    }
    

Added php code:

<?php
include($dir.'functions.php');
include($dir.'config.php');
include($dir.'ez_sql_core.php');
include($dir.'ez_sql_mysql.php');

///////////////////////////
$tableName = 'credentials';
///////////////////////////
$id = $_REQUEST['id'];


foreach($_REQUEST as $request => $value) {
    $_REQUEST[$request] = mysql_real_escape_string($value);
}

switch($_GET['action']) {
    case 'update':
       
       $update = "UPDATE $tableName SET name='".$_REQUEST['name']."',
            password=AES_ENCRYPT('".$_REQUEST['password']."', '$key'),
            code=AES_ENCRYPT('".$_REQUEST['code']."', '$key'),
            acct='".$_REQUEST['acct']."',
            priority='".$_REQUEST['priority']."',
            campaign='".$_REQUEST['campaign']."',
            username='".$_REQUEST['username']."',
            email='".$_REQUEST['email']."',
            url='".$_REQUEST['url']."',
            referralURL='".$_REQUEST['referralURL']."',
            extra='".$_REQUEST['extra']."'
            WHERE id='".$id."'";
            
        $success = $conn->query($update);

        if($success == 1)
            echo 'Updated record '.$id.': '.$update;
        else 
            echo 'Failed to update record '.$update;
        break;
        
    case 'delete':
    
        $query = "DELETE from $tableName WHERE id='".$id."'";
        $success = $conn->query($query);

        if($success == 1) 
            echo 'Successfully deleted record '.$id;
        else
            echo 'Failed to delete record '.$id;
        break;
        
    case 'create':
    
        $insert = "INSERT INTO $tableName (name, acct, priority, campaign, username, email, password, code, url, referralURL, extra) values (
            '".$_REQUEST['name']."', 
            '".$_REQUEST['acct']."', 
            '".$_REQUEST['priority']."', 
            '".$_REQUEST['campaign']."', 
            '".$_REQUEST['username']."', 
            '".$_REQUEST['email']."', 
            AES_ENCRYPT('".$_REQUEST['password']."', '$key'),
            AES_ENCRYPT('".$_REQUEST['code']."', '$key'),   
            '".$_REQUEST['url']."',         
            '".$_REQUEST['referralURL']."', 
            '".$_REQUEST['extra']."'
        )";

        $success = $conn->query($insert);
        
        if($success == 1) 
            echo 'Added record '.$insert;
        else 
            echo 'Failed to add record '.$insert;
        break;
    case 'read':
    default:
        $read = "SELECT *, AES_DECRYPT(password, '$key') as password, AES_DECRYPT(code, '$key') as code FROM $tableName WHERE id='".$id."'";

        $resR = $conn->query($read);        
        $recs = $resR->fetch_assoc();

        echo json_encode($recs);
        break;
}


?>
TheEmperor
  • 19
  • 3
  • 3
    If the problem occurs when you switch to PHP 7 then the problem is in the PHP code, not the JavaScript code. Probably, there's something in your PHP that is generating a warning or error with PHP 7 and that is corrupting or preventing your JSON output – Tangentially Perpendicular Jan 17 '21 at 22:45
  • Added the php code, please help – TheEmperor Jan 18 '21 at 06:34
  • 1
    There's a reference to `mysql_real_escape_string()` in this code. All the `mysql_*()` functions were removed in PHP7. At the very least you will need to update your code to use `mysqli_*()` or `PDO` equivalents. Note also that your code is vulnerable to SQL injection. You should take this opportunity to update to prepared statements. – Tangentially Perpendicular Jan 18 '21 at 08:50

1 Answers1

-1

It is as Tangentially Perpendicular said, this function was causing the error mysql_real_escape_string()

changed to mysqli_real_escape_string() And it worked

TheEmperor
  • 19
  • 3