Hello, Im trying to insert into an SQL database a description string via php. For some reason if there is a space the string gets cutted.
For example:
if i send out the String “Hello there!”
in the data base it is inserted as “Hello”
i have the field set as varchar. also try with text and long text…
Any idea what could be the problem there.
I do the String escape in the php file.
appels
2
the problem is most likely your php. varchar on the db should work fine.
<?php
$db = mysql_connect('localhost', 'xxxxxxx', 'xxxxxxx') or die('Could not connect: ' . mysql_error());
mysql_select_db('musclec1_game') or die('Could not select database');
// Strings must be escaped to prevent SQL injection attack.
$name = mysql_real_escape_string($_GET['name'], $db);
$time = mysql_real_escape_string($_GET['time'], $db);
$msg = mysql_real_escape_string($_GET['msg'], $db);
$query = "insert into globalChat values (NULL, '$name', '$time' , '$msg')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$get = "SELECT * FROM globalChat ORDER BY msgID DESC LIMIT 1";
$message = mysql_query ($get) or die ('Query failed: ' . mysql_error());
while ($row = mysql_fetch_assoc($message)) {
echo $row['name'] .": ". $row['message'];
}
?>
That’s the php…