Page 3 of 3 First 123
  • Jump to page:
    #31
  1. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Please post the complete code and the exact error message.
    The 6 worst sins of security How to (properly) access a MySQL database with PHP

    Why cant I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  2. #32
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    Main file:
    PHP Code:
    <?php 

        
    require("../connection.php"); 
         
        if(empty(
    $_SESSION['user'])) 
        { 
            
    header("Location: ../login.php"); 
            exit; 
        }  
    ?> 
    <html>
        <head>
            <link href="../style.css" rel="stylesheet" type="text/css" />
            <script src="../lib/jquery/jquery.min.js"></script>
            <script src="css_change.js"></script>
        </head>
        <body>
            <button type="button" onclick="css_func_1(0);">button 1</button>
            <button type="button" onclick="css_func_1(1);">button 2</button>
            <button type="button" onclick="css_func_1(2);">button 3</button>
            <button type="button" onclick="css_func_1(3);">button 4</button>
            <div id="css_change"></div>
        </body>
    </html>

    The javascript:
    Code:
    function css_func_1(id)
    {
    	$.getJSON('../lib/ajax/my_data.php', function(data) {
            document.getElementById("css_change").innerHTML="some css with 'data'";
            console.log(data);
        });
            
    }
    my_data.php:
    PHP Code:
    <?php    

    require '../connection.php'// connect to the database  

               
    header('Content-type: application/json');  

    $ids = array(1,2);  
    $db_data_stmt $db->prepare('   
        SELECT *   
        FROM table   
        WHERE id IN (' 
    implode(','array_fill(0count($ids), '?')) . ')    
    '
    );   
    $db_data_stmt->execute($ids);   
    $db_data $db_data_stmt->fetchAll();   
    $parsed_db_data json_encode($db_dataJSON_FORCE_OBJECT); 

    echo 
    $parsed_db_data;    // that's the relevant line!
    error message when I type console.log(data) in the console:

    Code:
    ReferenceError: data is not defined
    get stack: function () { [native code] }
    message: "data is not defined"
    set stack: function () { [native code] }
    __proto__: Error
  4. #33
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    You cannot type console.log(data) into the console, because data isn't defined in this context. It's a local variable, it only exists inside the function.

    So what's the actual error you get when running the code?
    The 6 worst sins of security How to (properly) access a MySQL database with PHP

    Why cant I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #34
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    ok, but I don't get a real error message except for that one. The (css) code doesn't get executed when I click the button.
  8. #35
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    I looked once again at the code but I don't see why it doesn't work... Please help
  10. #36
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    I am now so far that I know the script just doesn't execute the code in this statement:

    Code:
    $.getJSON('../lib/ajax/my_data.php', function(data) {
            document.getElementById("css_change").innerHTML="some css with 'data'";
            console.log(data);
    Surrounding console.log(); commands are executed.
  12. #37
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    Someone, please help, I don't know how to do this...
  14. #38
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    ...
  16. #39
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    Is there also an alternative?
  18. #40
  19. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Hi,

    what do you mean by "doesn't execute the code"? That the css_func_1() function isn't even executed? That the GET request isn't made? That the request callback isn't executed?
    The 6 worst sins of security How to (properly) access a MySQL database with PHP

    Why cant I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  20. #41
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    The GET request isn't made, I think that because only the code inside the statement doesn't get executed, so maybe the GET request is ignored or the data terminates the request or something...
  22. #42
  23. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    If you're saying that

    • the function is executed
    • the request isn't even initialized (no item in the "network" tab of the developer tools)
    • you're not getting any JavaScript error

    Then I'd say your browser is broken or misconfigured. Try a different one. If that still doesn't work, try a different PC.
    The 6 worst sins of security How to (properly) access a MySQL database with PHP

    Why cant I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  24. #43
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    367
    Rep Power
    8
    Thanks for the 'network' hint, it said the connection file was missing, so I changed the ../connection.php in ../../connection.php (because it was 2 directories down instead of 1) and now it works... sometimes those little things -_-
    I had ../connection.php because I thought if the file was requested, I was also executed in the main file (1 directory down, not 2) so I had ../connection.php ...

    But now it works, thanks again
Page 3 of 3 First 123
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo