Field with # does not appear in Mysql for _GET

Asked

Viewed 55 times

1

Good folks, I don’t know where to put the question..

I’m sorry if I’m in the wrong area!

Well, I’m racking my brain with a code on my page. The code works it sends the data to my database, only it is not sending a piece of the field for having this Character " # " there is only sending half.

Look at:

inserir a descrição da imagem aqui

The result is coming only the end of the nick code doesn’t arrive=Test"#6287"

Look at the result in the database: inserir a descrição da imagem aqui

File Code process.php

<?php
$conexao = mysqli_connect("phpmyadmin", "user", "pass");
mysqli_select_db($conexao, "db");


     $novoemail = addslashes($_GET["novoemail"]);
     $nick = addslashes($_GET["nick"]);

       $inserir = "INSERT INTO ajuda (id, email, usuario) VALUES (NULL, '$novoemail', '$nick');";
        mysqli_query($conexao, $inserir) or die (mysqli_error($conexao));
        echo"";
    ?>

2 answers

1

You’ll have to encode it, because the # direct is recognized by the browser with "dynamic URL" which is used primarily to interact in front-end, with HTML, CSS and Javascript, including made a response on the subject:

Having understood why this fails now let’s go to the step of correcting, for it to work you will have to encode (change in case) the # for %23, or is going to stay like this:

[email protected]&nick=teste%236287

But rest assured, when you use $_GET['nick'] will return teste#6287 perfectly.

If the link is generated by your script then for ease you can use urlencode(), more or less thus:

<?php
$email = urlencode('[email protected]');
$nick = urlencode('teste#6287');

echo '<a href="processar.php?novoemail=' . $email . '&nick=' . $nick . '">Link</a>';
?>

Something else, DON’T USE addslashes to escape in mysqli, this function may even work apparently, but does not have this purpose, even more depending on codecs (variations of utf8, latin1, etc.) around, so depending on the codecs maybe some character may cause syntax error, so do not do this:

 $novoemail = addslashes($_GET["novoemail"]);
 $nick = addslashes($_GET["nick"]);

The ideal is to use the proper function for this, mysqli_real_escape_string, thus:

 $novoemail = mysqli_real_escape_string($conexao, $_GET["novoemail"]);
 $nick = mysqli_real_escape_string($conexao, $_GET["nick"]);

0


What you may be doing is separating the shipping field :

meusite/ir/parse.php? [email protected]&nick=Teste&num=6287

And then "join" the two in PHP:

$nick = addslashes($_GET['nick'] . "#" . $_GET['num']);
  • But then I would have to create another variable to get the number? Because I already have a variable that takes the name#number together..

  • yes, anchors are not sent from the browser to the server.

  • you are picking up by input this information?

  • Yes I am. <span class="Lien-blanc-gras">Test#6287</span>

  • var nick = Document.getElementsByClassName("Lien-blanc-gras")[0]. textContent;

  • makes 2 <span>, one for nick and one for number

  • The page is not mine where I’m pulling the data so there’s no way I can do it.

  • 1

    then the way is to manipulate the text you want by changing the value of the string to upload and then changing the value again: --JS-var example = "Test#1234"; var result = example.replace("#", "."); Alert(result); --PHP-$nick = addslashes($_GET['nick']); $nickCorrigited = str_replace('.', '#', $nick); echo $nickCorrigited;

  • Got a friend thanks!!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.