尝试将js中的字符串写入mySql数据库时获取%%

I'm trying to create a simple interface to write values into a mySql database using js, php and html. When I hardcoded the value I wanted to write everything went fine, but now I want the retrieve the value from my input (.input) and use write that, and the value that gets written into my database is always %%. Can anyone please point out what I'm doing wrong? Thanks

$('#write').click(function() {
  writeTable();
})

// handles the click event, sends the query
function writeTable() {
  $.ajax({
    url: 'write.php',
    type: 'get', //data type post/get
    data: {
      name: $('input#input').val()
    },
    complete: function(response) {
      $('.output').html(response.responseText);
    },
    error: function() {
      $('.output').html('Bummer: there was an error!');
    }
  });
  return false;
}
.button {
  border: 1px solid black;
  width: 100px;
  display: inline-block;
}
.output {
  height: 400px;
  width: 400px;
  border: 1px solid black;
  overflow: auto;
}
<!doctype HTML>

<head>

  <meta charset="UTF-8">
  <link type="text/css" rel="stylesheet" href="index.css">

</head>

<body>

  <br>
  <form>File Name:
    <input type="text" name="input" placeholder="Type something">
  </form>
  <br>
  <div class="button" id="write">Write</div>
  <div class="button" id="search">Search</div>
  <br>
  <br>
  <div class="output"></div>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="index.js"></script>

</body>

php:

<?php
// Attempt MySQL server connection *
$link = mysqli_connect("localhost", "topdecka_admin", "kR4lJm1H4!", "topdecka_MTGO");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$data = "%".$_GET['name']."%"; //get data from javascript

// Attempt insert query execution
$sql = "INSERT INTO drafts (picks) VALUES ('$data')";

if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>
</div>

It is a good practice to put a condition check before INSERT

$data = "%".$_GET['input']."%"; //get data from javascript 
if (empty($_GET['input'])) {
    echo 'name input cannot be blank';
}else {
$sql = "INSERT INTO drafts (picks) VALUES ('$data')"; }

Before the insert check what you are getting in $_GET['input']. Try to print $_GET['input'] first, put a condition check, if its null (as it is in your case), do not execute the INSERT statement

See these lines:

$data = "%".$_GET['name']."%"; //get data from javascript

Are you sure you want the "%" symbol before and after the get variable? Try this:

$data = $_GET['name']; //get data from javascript