Jump to content

mrbean

Members
  • Posts

    85
  • Joined

  • Last visited

Posts posted by mrbean

  1. Sorry to be blunt, but your code is a gross misuse of a class/oop and variable variables, to the point that you don't even know the variable name that your query's result resource is in. Hint: it's not in $checkfirstime.

     

    One of the points of using classes/oop is the code and data needed for any particular purpose is encapsulated/self-contained. By using the global keyword and a variable variable on top of that, you are breaking that encapsulation/self-containment.

     

    Another point of functions/class methods is that they return the result they produce. Your ->query() method should return the false/true/result resource and you assign that to a program variable - $result = $database->query(.....);

     

    Forget you ever saw the global keyword and variable variables. They result in code that you won't be able to troubleshoot simple problem with (and would get you fired from a large project where unexplained values changing due to them will cause a bunch of wasted time for the team working on the project.)

     

    --------------------------------

    Some hints for your class -

     

    1) The type should be stored in a class property. The rest of the class code uses that stored value.

     

    2) You should pass the database connection details/database name into the class, either in the constructor or using a specific 'setter' class method call.

     

    3) The database link resource should be stored in a class property, i.e. $link (there's no need to have separate $mysql, $mysqli, $mssql since any one instance of your class can/should only operate on one database type.)

     

    4) The query method should return the result from the query.

     

    Thank you for your help, I will change my class after I fixed this.

    I have changed the code, and tried this:

    $userdata = mysql_query("SELECT `first_time`, `money`, `life` FROM users WHERE 'username' = 'demo'");
    $user = mysql_fetch_object($userdata)or die("ERROR: ".mysql_error());
    echo $user->money;
    

    Result:

    ERROR:
    

    post-92629-0-50023500-1355868931_thumb.png

  2. I have a little problem i hope someone can help me with it.

     

    Here's the code:

    <?php
    session_start();
    echo $_SESSION['username']; // result: demo
    include($_SERVER['DOCUMENT_ROOT']."/database.php");
    $database = new database("mysql");
    $database->query("SELECT `first_time`, `money`, `life` FROM `[users]` WHERE `username` = '".$_SESSION['username']."' ","userdata");
    $user = mysql_fetch_object($checkfirstime);
    ?>
    

     

    Database:

    http://ctrlv.in/145476

     

    Database.php:

    <?php
    class database
    {
    public function __construct($type)
    {
    global $server,$username,$password,$databasename,$querytype,$mysql,$mysqli,$mssql;
    if($type === "mysql")
    {
    $mysql = mysql_connect($server, $username, $password)or die("kan geen verbinding maken met de server, de volgende error is voortgekomen:".mysql_error());
    mysql_select_db($databasename, $mysql)or die("kan geen verbinding maken met de database, de volgende error is voortgekomen:".mysql_error());
    }
    else if($type === "mysqli")
    {
    $mysqli = new mysqli($server, $username, $password, $database);
    }
    else if($type === "mssql")
    {
    $mssql = mssql_connect($server, $username, $password);
    mssql_select_db($database, $mssql);
    }
    $querytype = $type;
    }
    public function query($query,$naam = "GEEN")
    {
    global ${$naam},$querytype;
    if($querytype === "mysql")
    {
    ${$naam} = mysql_query($query)or die('error in '.$naam.': '.mysql_error());
    }
    else if($querytype === "mysqli")
    {
    ${$naam} = $mysqli->query($query)or die('error in '.$naam.': '.mysql_error());
    }
    else if($querytype === "mssql")
    {
    ${$naam} = mssql_query($query)or die('error in '.$naam.': '.mysql_error());
    }
    }
    }
    ?>
    

     

    The error I get:

     

    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in engine.php on line 7
  3. Does someone know what they mean by "channelURL" in:

    <div id="fb-root"></div>
    <script>
     // Additional JS functions here
     window.fbAsyncInit = function() {
       FB.init({
         appId      : 'YOUR_APP_ID', // App ID
         channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
         status     : true, // check login status
         cookie     : true, // enable cookies to allow the server to access the session
         xfbml      : true  // parse XFBML
       });
    
    
       // Additional init code here
    
    
     };
    
    
     // Load the SDK Asynchronously
     (function(d){
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
      }(document));
    </script>
    

     

    Does someone have also an example?

  4. I know this sounds stupid/dump but i need your help.

     

    I've got this:

    2e4elh3.png

    I want this:

    11ruanr.png

     

    In facebook developers page, they show some examples. I tried it but didn't get what I want.

     

    Can someone help me with it?

  5. Why are you using error suppression if not to hide errors? In fact why are you suppressing errors at all? Fix them instead.

    What exactly are you trying to accomplish?

     

    If the include statement is failing, the file isn't being included. If it's not being included, it's not being parsed, tokenized, and interpreted. if it's not being parsed, tokenized, and interpreted, there's no way to find and report the errors in it.

     

    I will explain it to you guys.

     

    I have 2 files.

     

    One is the file with the functions

    The other file will include the functions file.

    For example:

    The function file contains:

    <?php
    class sadasd
    {
    function
    function
    }
    class lsadasd
    {
    function
    function
    function with an error
    }
    ?>
    

    File that includes the function

    <?php
    $functions_file = @include(dirname(__FILE__)."/functions.php");
    if(!($functions_file))
    {
       $try_default_functions_file = @include(dirname(__FILE__)."/functions.php");
       if(!($try_default_functions_file))
       {
           echo "<h1>Error</h1><br>";
           echo "kan de functies bestand niet vinden.<br>";
           echo "Could not find the functions file.<br>";
           exit;
       }
       echo "error with including file.";
    }
    $test = new function();
    $test->something();
    //this should return test
    echo "test";
    ?>
    

     

    Because the function.php an error contains nothing is shown.

    I only want to suppress the function "include" if it fails trigger an custom error to prevent hackers to see further info.

    But not if there is an internal error in function.php

  6. Verry simple to explain:

    If i suppress the include function, everything whats in it will not trigger an error instead the page returns white.

    @include("filewitherrors.php");
    

     

    How can I suppress the include function but not effect the file?

  7. for example I have 2 forms:

    <form id="login_form" action="submit.php">
    <input type="text" name="username">
    <input type="password" name="password">
    </form>
    
    <form id="signup_form" action="submit.php">
    <input type="text" name="username">
    <input type="password" name="password">
    </form>
    
    

    With php I want to determinate if one of them is submitted.

    If it is, do something with the password + username.

     

    Both have the same input name, but is it possible to select only the inputs of a specific form even if they have the same name as other forms? If yes, how?

  8. Where did I say it was a requirement?? See above.

     

    I'm not on about the function definitions..

    Then what are you talking about? I said you should not run jquery code outside of the doc ready. If you guys both interpreted that wrong fine, but that's what I said.

    I understand you should not do that. If you are talking to me?

  9. Where did I say it was a requirement?? See above.

     

    I'm not on about the function definitions..

    Thanks for your replies Adam.

     

    Found it!

     

    $(document).ready(function() {

     

        test=function(){ alert(123); }; // global var :D

     

    });

  10. <script></script>....

     

    Are you actively trying to get people to ignore you, or what? We're not here to do the work for you, you know. We've got plenty of other, and better, stuff to do than to spend our free time doing the basic research for you. If you can't be arsed to spend a little bit of time researching the bascis, why should we be arsed to spend our time doing it for you?

     

    Read ManicDan's signature.

     

    Could you please please be more friendly.

    And sorry for my english, I am not an expert in it.

    Like Adam said, I thought there is an function to import an external file. Just like java.

    example: import my.package.MyClass;

     

    @jesirose,

     

    It doesn't work.

    Why? Just like Adam said:

    ".....So when you define test() within document event, you're restricting it to just that anonymous function."

     

    And everytime I start a new:

    $(document).ready(function(){

    });

     

    It will create a new unique anonymous function. Those functions created in the anonymous function will be only available in the anonymous function itself.

     

    For example, this won't work:

     

    Index.html

    <html>
    <head>
    <script language="JavaScript" src="first.js">
    </script>
    <script language="JavaScript" src="second.js">
    </script>
    </head>
    <body>
    Just some content.
    </body>
    </html>

    First.js

    $(document).ready(function(){
    function test(){
    alert("This is a test");
    }
    });
    

    Second.js

    $(document).ready(function(){
    test();
    });
    

     

    ERROR: start is not defined.

     

     

    I can define it outside of document ready, but I want to work within the document ready function.

    Just to wrap the code and be more organized.

     

    Sorry for my english.

  11. My code is like this:

     

    $(document).ready(function() {

    function test(){}

    });

     

    Out of the ready function I want to execute test(), so in another js file:

     

    test();

     

    But if I run the code, I get an error that test(); is not defined.

     

    How to solve this?

  12. Why doesn't this work?

     

    var candy = new Array(new Array());
    for (var i = 0; i < 10; i++) {
        candy[i][i] = "Sweet!";
      }
    

     

    The error that I get from chrome is:

    Uncaught TypeError: Cannot set property '0' of undefined

     

    I want to make an multidimensional array in an loop without knowing how long it can be.

  13. What you're asking to do doesn't make any sense. Why would you want to refer to the image by it's src of test01.png, when you know you can access it through image[1]? Sounds like you're trying to over complicate things.

     

    I am not asking that, but it's already fixed :)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.