drayarms's Profile User Rating: -----

Reputation: 4 Apprentice
Group:
Active Members
Active Posts:
188 (0.12 per day)
Joined:
18-May 11
Profile Views:
2,349
Last Active:
User is offline Jul 29 2015 11:52 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   drayarms has not set their status

Posts I've Made

  1. In Topic: How to convert javascript integer into PHP integer?

    Posted 27 Jul 2015

    View PostArtificialSoldier, on 27 July 2015 - 09:00 AM, said:

    I told you why it works, because your browser sees the Javascript code in the string and executes it. That's why the length of the string is off. If you don't believe me, open your browser so you see the query printed with the 1, and then right-click and view the HTML source. You will not see PHP printing a number 1, you will see Javascript code that your browser is executing and printing 1. That's also why there is an extra "space" after the 1 - because you used document.writeln (the space is the line break at the end from writeln).

    In short, when you print $number you are printing Javascript code that your browser is executing, you are not printing the number 1 from PHP.


    Makes sense. Thank you for the explanation. I've abandoned this approach in favor of some other less convoluted approach involving Ajax.
  2. In Topic: How to convert javascript integer into PHP integer?

    Posted 25 Jul 2015

    View PostMartyr2, on 24 July 2015 - 12:16 PM, said:

    Well first you can't do that. Javascript here is client side and PHP is server side. Meaning that your number JS variable is not available at the time that the PHP on page B is being executed. Second of all, let's take a look at this code here...

    $number = "<script>document.writeln(localStorage.getItem('number'));</script>";
    	
    	
    	//And run the query
    
    	$query = "SELECT * FROM table WHERE number = '$number' ";
    
    


    Here $number is a string of JS, nothing else. That JS is not executed or anything so when you put it in the query I am not even sure how you are even getting a number at all. Your query should be reading...

    $query = "SELECT * FROM table WHERE number = '<script>document.writeln(localStorage.getItem('number'));</script>' ";
    
    


    Which is obviously not going to work. PHP can render JS, JS can pass values to other PHP pages via AJAX requests and read in through post parameters, but how you are mixing them here is not making sense. Read my blog about this topic...

    http://www.coderslex...o-php-and-back/

    Are you perhaps leaving out some steps?





    I understand the difference between server and client side scripting. But notice in this case that I'm adding a piece of javascript code to the document on the server side, just as I can any html element, assigning the output of that code to a PHP variable, then sending it to the client. I didn't expect it to work at first, but when I tried it, it seemed to work. How else would I get '1 ' in the var dump? I even tried
    echo $number
    
    just to make sure and sure enough, I got a '1' printed on the page.
  3. In Topic: How to convert javascript integer into PHP integer?

    Posted 25 Jul 2015

    View PostArtificialSoldier, on 24 July 2015 - 12:50 PM, said:

    Quote

    The var_dump yields this:

    string(162) "SELECT * FROM table WHERE number = '1 ' "

    Hmm, that's misleading you. First, notice that it says string(162) - 162 is the length. That query doesn't look like 162 characters, it looks like much less, so why it is claiming the variable is 162 characters long? It's because you are printing the Javascript code and the browser runs it and shows the number 1 there instead.


    Well I had to remove some other table columns and associated values from the WHERE clause in the query because I only wanted to include information relevant to the problem. That's why the var dumb string length does not match what I posted.
  4. In Topic: How do I fwrite a php variable into text input

    Posted 12 Jun 2015

    @artificialsoldier yup that's where the problem stemmed from. I was missing those quotes. So instead of
     value = ".$submitted_var."
    
    I did
    value = '".$submitted_var."'
    


    I'm however thinking that It's much easier and less problematic to just use hidden divs instead of hidden form inputs
  5. In Topic: How do I fwrite a php variable into text input

    Posted 11 Jun 2015

    Ok thanks that seems to work but the output is a url encoded string. So "hello world" is displayed as "hello+world". I try to use urldecode to get back the original text but it just leaves me with the original problem (trauncated texts).

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

drayarms hasn't added any friends yet.

Comments

drayarms has no profile comments yet. Why not say hello?