Fengist's Forum Posts

  • the error now returns:

    No user found with that name.

    That's perfect!

    That means that the username you searched for wasn't in the database. That's good because it means there were no errors. You connected to the database, you performed a query but it returned 0 results.

    Now, all you have to do is add a user to the database and search for them.

    Binding params is relatively new to php. It's purpose is to prevent things like SQL injection when getting query strings like $_GET. Basically, the way it works is this.

    In your query you substitute the ? for the insecure variables you want to put in the query.

    You then prepare the query. Then you bind the variables to the query. In the bind_param the 's' simply tells the bind command that you're passing a string and it substitutes the first ? (which it now knows is a string) for the $_GET["name"]. If you have say 3 ?'s in your query:

    SELECT id from user where username = ? and birthday = ? and country = ?

    $stmt->bind_param("sss", $_GET["username"], $_GET["birthday"], $_GET["country"])

    Then, you execute the query and finally get the results.

    Very glad you got it working!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ok, I'm wholly unfamiliar with PDO and how it connects but the error you're getting is because it's failing to make a connection to the database so we need to do some error checking. I'm making a guess that you're using MySQL so let's try establishing a mysql connection instead:

    You currently have the PDO password set to '' which means, you aren't using one. I have yet to see an install of MySQL that allows no password on the root account unless you specifically set it to none.

    In the script below, you're going to need to replace DB_PASSWORD with the password you used when you set up the root account and put it inside single quotes like this:

    'password'

    If you're sure you don't have a password for that database then replace DB_PASSWORD with:

    ''

    Hopefully, this will work. Just run this from the browser. Once it does work, you can add in the:

    header('Access-Control-Allow-Origin: *');

    Back at the top.

    Take note, this produces a string as the AJAX result. From what I saw you had the result set to a number. If this does work, you will need to change it to see the errors.

    <?php
    $base = new mysqli('localhost', 'root', DB_PASSWORD, 'stockage');
    // Check connection
    if ($base->connect_errno) {
     die("Failed to connect to MySQL: " . $base->connect_error);
    }
    
    $sql = "SELECT id FROM user where username = ?";
    
    if (!$stmt = $base->prepare($sql))
    {
     echo "Prepare failed: (" . $stmt->errno . ") " . $stmt->error;
    }
    if (!$stmt->bind_param("s", $_GET['name'])){
     echo "Bind failed: (" . $stmt->errno . ") " . $stmt->error; 
    }
    if (!$stmt->execute()){
     echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error; 
    }
    if (!$result = $stmt->get_result()) {
     echo "Get result failed: (" . $stmt->errno . ") " . $stmt->error; 
    }
    if ($result->num_rows > 0) { 
     $row = $result->fetch_object();
     echo $row->id;
    }
    else
    {
     echo 'No user found with that name';
    }
    ?>
    
  • Because now you changed $base to $bdd

    <?php
    
    try
    {
     $base = new PDO('mysql:host=localhost;dbname=stockage;charset=utf8', 'root', '');
    }
    catch (Exception $e)
    {
     die('Erreur : ' . $e->getMessage());
    }
    	$sql = "SELECT id FROM user where username = ?";
    	$stmt = $base->prepare($sql);
    	$stmt->bind_param("s", $_GET['name']);
    	$stmt->execute();
    	$result = $stmt->get_result();
    	$row = $result->fetch_object();
    	echo $row->id;
    
    ?>

    Assuming you have a table named user with a field username and a field id (and those are case sensitive) this should work.

    login.php?name=theusername should give you the ID

    Once it works, but this back at the top:

    header('Access-Control-Allow-Origin: *');

  • Then you need to check and see if the php file is actually working by going directly to the URL.

    http://www.mysite.com/phpfilename.php?name=username.

    Nextly, you removed the

    header('Access-Control-Allow-Origin: *');

    which means, when AJAX tries to connect to that php file, it will get an error and/or return nothing.

  • There's an overflow-x and overflow-y under 'inline style' you'll have to set.

    It looks like the overflow-y is set to not in use or visible. Try setting the overflow-y to auto or scroll and set the overflow-x to hidden and see if that doesn't produce your expectations.

    That should force the plugin to keep the text inside the element and produce a vertical scroll bar.

  • You changed the sql?

    SELECT id FROM members where username = ?

    SELECT id FROM user where username = ?

    Which is the correct name for the table you're trying to read from?

    What errors are you getting if any? What is the AJAX.LastRequest showing?

  • Ok, does it work?

  • If it's a small set you could use choose.

    choose("This text","That text","The other text")

  • And a quick thank you for posting all those images. Made figuring out the problem SOOO much easier.

  • First, you're loading the json wrong:

    It should be

    -> Array: Load from JSON string AJAX.LastData

    Next, you're trying to get 1 dimensional data from a 2 dimensional array.

    Try this:

    -> Text: Set text to Array.At(1,1)

    That should be "B"

    0,1 should be "b"

    Have a question though, why are you using an array when you can uppercase("b") and get "B"

    You could do a choose("a","b","c"... etc.) to get a random letter, stuff that into a variable and then compare user input to uppercase(variable)

  • Yes. Whether you succeed depends on your skills and knowledge.

  • You realize that a 2pt font would be so tiny as to be unreadable?

    https://www-archive.mozilla.org/newlayout/testcases/css/sec526pt2.htm

    2pt is the second one from the top.

    That is this reply in 2pt as seen by Chrome. So, Chrome does do 2pt.

  • Have you looked at the HTMLElement plugin?

    construct.net/en/make-games/addons/190/html-element