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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert from PHP won't save Strings with Spaces? 1

Status
Not open for further replies.

Tasuki

MIS
Jul 26, 2002
169
US
Hi, I've search th

I have I think two problems with my INSERT. I've searched through the forums and did some googling without much luck.

I have a form that sends/posts the collected entries to a processing form which performs some checks to see if data entry meets all requirements, and redisplays the data they entered by re-invoking the $fields. The user can look it over to see if everything is correct before submitting the data to be inserted into the database. Note: When I echo back the results from the form, all fields are correct and are not cut off (explained below).

But the problem is, if the user enters in data like this:

PictName: 'endang seaturtle.jpg' (just a string, no images stored in DB)
Comments: 'Buoy is in for repairs'

The data that is saved in MySQL database for Location is just "endang" and for the Comments, "" (empty/blank). Most of the fields are just one word length and insert perfectly fine.

Location VARCHAR(20) NULL DEFAULT NULL
Comments VARCHAR(200) NULL DEFAULT NULL

My Insert looks like this:

$query = "INSERT INTO tblNetDesc (SubSample, InitialDate, NetClassID, PictName, Comment) VALUES ('$subsample', '$the_date2', '$netclassid', '$picturename', '$comment')";
$result = mysql_query($query) or die ($query.mysql_error());

Also if it helps, PictName is an input field and Comment is a textarea field on the form.

How come it won't save the white space? Why isn't the comment field saving?

Any help greatly appreciated.

Thanks for looking,

-T
 
is it failing on the insert or the display when you try to display? The code in your example looks correct

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
No fails, it runs perfectly... just cuts off anything after the space, and the comment field just won't take. All other fields insert perfectly.
 
Oh, as for the display, it displays the full comment when I use $comment in PHP and the full picturename when I use $pictname. And those are the exact same variables are passed to mysql... hmm I'm stumped.

Thanks for looking,

-T
 
I'd add "echo $query" to the php file and see the actual SQL string. It looks ok, though.
 
Ahh thanks... turns out from the Process Form to the Execution of the Insert Query, it decided to start chopping off the end of strings that had spaces in them. So I changed the hidden field values and added ' quotes ' so that the entire string is passed.

But for some reason, when trying to extract and display the comment field data from the database, I get a blank, while all other fields are returned correctly including the pictname with spaces. Well, that's another problem to deal with...

Thank you for the debugging help.

-T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top