How can I insert a '+' symbol into a MySQL database with PHP? -


this php script

<?php  require_once('db.php');  $data = $_get['data']; $data = mysqli_real_escape_string($conn, $data);  $otherdata = $_get['otherdata']; $otherdata = mysqli_real_escape_string($conn, $otherdata);  $query = "insert dataone (data, otherdata) values (?, ?)";  $stmt = mysqli_prepare($conn, $query);  mysqli_stmt_bind_param($stmt, "ss", $data, $otherdata); mysqli_stmt_execute($stmt);  $affectted_rows = mysqli_stmt_affected_rows($stmt);  if($affectted_rows == 1) {      echo 'data submitted';      mysqli_stmt_close($stmt);      mysqli_close($conn);  } else {     echo 'error occurred<br/>';     echo mysqli_error();     mysqli_stmt_close($stmt);     mysqli_close($conn); }  ?> 

it works fine, when add + symbol in url, doesn't inserted wanted to.

this tried: http://example.com/data.php?data=10+2&otherdata=test

but inserts data 102 instead of 10+2

how can include '+' symbol in database?

you must use urlencode()

 $otherdata = urlencode ($_get['otherdata']); 

Comments