Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to escape space on INSERT?

Status
Not open for further replies.

georgeocrawford

Technical User
Aug 12, 2002
111
GB
Code:
<?php

$object_name = mysql_real_escape_string($array[$i]);
$query = &quot;INSERT INTO $table (`object_name` , `type` , `parent`, `size`) VALUES ('$object_name', '$type', '$parent', '$size')&quot;;
$result = mysql_query($query);
$parent = mysql_insert_id();
$query = &quot;SELECT * FROM `$table` WHERE `object_id` =$parent&quot;;
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))			
{
	echo &quot;inserted name = '$row[object_name]'\n&quot;;
}

?>

When the object_name is, for example &quot;my file with a space &quot;, the trailing space is not entered into the database. How can I escape it?

______________________

George
 
are you sure its not entered into the database - or is it html not showing the space as trailing?

str_replace(' ','*',$string);

and identify all spaces with ease :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Nope - definitely not. The above will show * for spaces WITHIN the filename, but not a trailing space.

I even tried echoing the 'INSERT' query, to check the space was definitely sent to the database, and it was.

The table in question has a field type of varchar(100), if it's important.

______________________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top