Field with # does not appear in Mysql by _GET

1

Good people, I do not know where to put the question ..

Excuse me if you're in the wrong area!

Well, I'm breaking my head with a code on my page. The code works it sends the data to my database, but it is not sending a piece of the field because it has that "#" character there, only sending half of it.

Look:

#6287

Theresultisonlymissingtheendofthenickname=

Lookattheresultinthedatabase:

FileCodeprocess.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"";
    ?>
    
asked by anonymous 15.08.2018 / 19:42

2 answers

0

What you might be doing is separating the upload field:

  

mysite / go / process.php? [email protected]& nick = Test & num = 6287

And then "join" the two in PHP:

$nick = addslashes($_GET['nick'] . "#" . $_GET['num']);
    
15.08.2018 / 20:05
1

You will have to encode it, because # direct is recognized by the browser with "Dynamic URL" that is used to mainly interact in the front end, with HTML, CSS and JavaScript, I even made a response on the subject:

Having understood why this fails, now let's go to the step of correcting, so that it works you will have to code (change in the case) the # to %23 , or it will look like this:

[email protected]&nick=teste%236287

But be calm, when using $_GET['nick'] will return teste#6287 perfectly.

If the link is generated by your script then to facilitate you can use urlencode() , more or less like this:

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

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

Another thing, DO NOT USE addslashes to escape in mysqli , this function may seem to work, but does not have this purpose, even more depending on codecs (variations of utf8, latin1, etc.) so depending on the codecs maybe some character may cause a 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 , like this:

 $novoemail = mysqli_real_escape_string($conexao, $_GET["novoemail"]);
 $nick = mysqli_real_escape_string($conexao, $_GET["nick"]);
    
15.08.2018 / 21:08