I've got a strange problem, have a look at this code:
$query="SELECT device_name, ip, method, port
FROM devices
WHERE device_name='".$_POST['name']."'";
When I post in 'name' -> 'test' (text without spaces) it works (returns some values I want). But in this situation for example 'name' -> 'test test' (text with space) it returns empty values, but shouldn't.
At last, when I tried this:
$query="SELECT device_name, ip, method, port
FROM devices
WHERE device_name='test test'";
It returned the values I want.
Why does it make problem when I use $_POST['name']
in my SQL code?
Certainly, I've tried saving $_POST['name']
in a variable and then put it into the SQL code, also using ( `` )
, ( [ ] )
than ('')
doesn't do the trick. I am working with MySQL.
Any ideas?
The var_dump() of $_POST['name']:
<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'WIM'</font> <i>(length=3)</i>
And I see, that $_POST['name'] contains only the word after the space. Why?