-1

I got these files:
Updating script:

<script>
    function TradeURLTimer() {
        setInterval(function(){
            jQuery.ajax({
                url: "assets/cores/check_username.php",
                data:'TradeURL='+$("#TradeURL").val(),
                type: "POST",
                success:function(data){
                $("#username-availability-status").html(data);
                },
                error:function (){}
            });
        }, 3000);
    }
</script>

My check_username.php:

<?php
// Variables to connection
$mysql_hostname = "localhost";
$mysql_user = "*******";
$mysql_password = "*********";
$mysql_database = "**********";
$prefix = "";
// Create connection
$conn = mysql_connect($mysql_hostname, $mysql_user, $mysql_password);
$connect = mysql_select_db($mysql_database, $conn);

$TradeURL=$_POST['TradeURL'];
$count_TradeURLs = mysql_num_rows(mysql_query("SELECT * FROM users WHERE TradeURL='$TradeURL'"));
switch ($count_TradeURLs) {
    case "0":
        ?>
        <section class="feed-item col-md-2 pull-left">
            <div style="padding-top: 5px;" class="icon">
                <i class="fa fa-check color-green"></i>
            </div>
        </section>
        <?php
        echo $TradeURL;
        break;
    case "1":
        ?>
        <section class="feed-item col-md-2 pull-left">
            <div style="padding-top: 5px;" class="icon">
                <i class="fa fa-remove color-red"></i>
            </div>
        </section>
        <?php
        break;
}
?>

My inserted text $_POST['TradeURL'] is =
https://steamcommunity.com/tradeoffer/new/?partner=53756765&token=bnsKYKib
But somehow when I ask the check_username.php to echo the variable $TradeURL, then it is only
https://steamcommunity.com/tradeoffer/new/?partner=53756765

So something is removing the last part of the link:
"&token=bnsKYKib"
Why does this happen? I can't figure it out. I tried to convert it into a string and split it, but still the same outcome...

bilbodog
  • 231
  • 1
  • 5
  • 15
  • 1
    Try to log this **$("#TradeURL").val()** using `console.log( $("#TradeURL").val() )` and check browser console before ajax call. – Devendra Singh Bhandari Oct 31 '15 at 16:18
  • 1
    The POST variables are separated with "&" when sended to the url (in this case: assets/cores/check_username.php). That's why your value gets truncated after & – leonardo_palma Oct 31 '15 at 16:21
  • I just tried to do so, @DevendraBhandari, but still same outcome. Thanks anyway for trying! – bilbodog Oct 31 '15 at 16:25
  • Okay, @leonardo_palma. Are there anyway to fix this problem. A different way to do it? – bilbodog Oct 31 '15 at 16:26
  • Isn't it possible to issolate it somehow, to force a variable to take place? – bilbodog Oct 31 '15 at 16:27
  • Here is the solution @bilbodog: http://stackoverflow.com/questions/3319123/how-to-escape-in-a-post-request-in-jquery – leonardo_palma Oct 31 '15 at 16:29
  • `error_reporting(0);` that turns error reporting OFF, why are you doing that? Set it to catch and display http://php.net/manual/en/function.error-reporting.php and check your console. – Funk Forty Niner Oct 31 '15 at 16:40
  • It is not quite the solution. I don't really get it. I don't want a table full of variables. I just wanna get my full link. I made this: data:'TradeURL='+$("#TradeURL").val()+"&token="+token, – bilbodog Oct 31 '15 at 16:44
  • I know @Fred -ii-. It was actually a temporarily thing. I have already removed it. That is my bad. But thanks for the heads up! :D – bilbodog Oct 31 '15 at 16:45

1 Answers1

1

As @leonardo_palma pointed out, your TradeURL variable is being parsed by PHP. You have to encode it to send it to the other page, and then to decode it. Here is how you can do it:

updating script:

// ...
data: 'TradeURL='+encodeURIComponent($("#TradeURL").val()),
// ...

check_username.php:

// ...
$TradeURL = urldecode($_POST['TradeURL']);
// ...
ZeusInTexas
  • 309
  • 1
  • 7
  • You are my god, @ZeusInTexas! It works. Thank you a lot man! I have been struggling with that problem since 11 PM yesterday. You definitely made my day. :D – bilbodog Oct 31 '15 at 16:48