views:

78

answers:

3

EDIT 2: After writing up an incredibly long explanation in more detail I, of course, discovered my problem and it had nothing to do with the question I asked. It was caused because I was creating a custom object of mine, assigning an uploaded images name to it's "LogoName" property...then creating a new version later in code, not assigning that property to the new object and then trying to save the new object (with no LogoName set) to the database.

Sorry to have wasted your time. Thank you for your answers. They have all been upvoted. END EDIT 2

I have a form in a php site. The form has the usual City, State, Zip input options. City looks like this:

<label for="city">City</label><input type="text" name="city" value="<?php echo $business->city; ?>" id="city">

Zip looks like this:

<label for="zip">Zip</label><input type="text" name="zip" value="<?php echo $business->zip; ?>" id="zip">

When I check my $_POST the values look like this: (using FirePHP)

['city'] => 'St. Louis'
['zip'] => 12345

So naturally when I put those values into my object, and try to save that object to the database (which has Zip as a varchar) I get errors because Zip is recognized as an integer.

How do I tell the form to force the Zip value in the $_POST as a string?

EDIT: I didn't even think about this but maybe it's relevant. The form is set up to allow an image upload as well so the form has enctype="multipart/form-data" set. Could that be causing this issue?

Other than that I don't know what to think as I am using FirePHP to log the $_POST information pretty much as soon as the form loads on Submit. I can't think of anything that would cause this issue.

+4  A: 

You could cast it to a string like this

$zip = (string) $_POST['zip'];
alex
he is trying to convert to string not to int.
Yes, I realised my mistake and updated my answer.
alex
+1  A: 

You can do strval($var);
or $val.""; :)

+1  A: 

I tried your example, but get

    [zip] => 12345
    [city] => Anywheresville

Normally, one doesn't have to worry about integers not looking like strings. I'm hard pressed to think of a case where a reasonable conversion wouldn't happen automatically. May be you could post the code which forms the structure and generates the query?

wallyk