andyd34 Posted September 14, 2009 Share Posted September 14, 2009 I have a form that is submitted via jquery into a mysql database using php <form method="post" name="add_loc_form" id="add_loc_form"> <table width="100%" align="center" cellspacing="0"> <tr> <td class="cat"><h2>Add Location</h2></td> <td align="right" class="cat"><a href="#" class="loc_help_a"><img src="{T_THEME_PATH}/images/help.gif" /></a></td> </tr> </table> <div id="loc_help" style="width:95%; display:none; padding:2.5%; background-color:#FFE9D2"> help txt</div> <table width="70%" align="center"> <tr> <td valign="top">latitude</td> <td valign="top"><input type="text" name="loc_long" id="loc_long" size="20" /></td> </tr> <tr> <td valign="top">Longitude</td> <td valign="top"><input type="text" name="loc_lat" id="loc_lat" size="20" /></td> </tr> <tr> <td valign="top">Place name</td> <td valign="top"><input type="text" name="loc_place" id="loc_place" size="40" /></td> </tr> <tr> <td valign="top">Description</td> <td><textarea cols="30" rows="3" id="loc_desc" name="loc_desc"></textarea></td> </tr> <tr> <td colspan="2" align="center" valign="top"><input type="submit" value="add" name="add_loc" id="add_loc" /> <button class="close_add_loc">close</button></td> </tr> </table> </form> Its is then passed to the jquery $("#add_loc_form").submit(function() { var loc_long = $('#loc_long').val(); var loc_lat = $('#loc_lat').val(); var loc_place = $('#loc_place').val(); var loc_desc = $('#loc_desc').val(); var dataString = "loc_long="+ loc_long +"&loc_lat="+ loc_lat +"&loc_place="+ loc_place +"&loc_desc="+ loc_desc; if(loc_long=='') { $("loc_long").css("border-color:red"); return false; } if(loc_lat=='') { $("loc_lat").css("border-color:red"); return false; } if(loc_place=='') { $("loc_place").css("border-color:red"); return false; } if(loc_desc=='') { $("loc_desc").css("border-color:red"); return false; } $.ajax({ type: "POST", url: "./ajax.php", data: dataString, success: function() { $('form').clearForm(); $("#add_map_locations").fadeOut(600); $("#map_add_success").fadeIn(600); } }); return false; }); the php is mysql_query("INSERT INTO table_locations (longitude, latitude, place_name, description, user_id) VALUES ('$loc_long', '$loc_lat', '$loc_place', '$loc_desc', '$user_id')"); The problem is when each entry has a number in it its submitting a rounded number to the database ie loc_long's value is -2.329102 but its submitting -2 for some reason, if you put numbers in the place or description fields its saving as a rounded number as above. If you put text in any of the fields its saving 0 instead of the text. The fields in the database as set to varchar so its not that. Can anyone help please. Quote Link to comment Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Sounds like you're using the wrong data type, integer i imagine? Try float for numbers with decimal points and varchar for mixed text. Edit: Ohhh missed that last bit. Can you post the table structure? Quote Link to comment Share on other sites More sharing options...
andyd34 Posted September 14, 2009 Author Share Posted September 14, 2009 As stated in origional post The fields in the database as set to varchar so its not that. They are set to varchar. Quote Link to comment Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Yeahh.. Edit: Ohhh missed that last bit. Can you post the table structure? Quote Link to comment Share on other sites More sharing options...
andyd34 Posted September 14, 2009 Author Share Posted September 14, 2009 `id` int(15) NOT NULL auto_increment, `longitude` varchar(15) collate utf8_bin NOT NULL, `latitude` varchar(15) collate utf8_bin NOT NULL, `place_name` varchar(60) collate utf8_bin NOT NULL, `description` varchar(200) collate utf8_bin NOT NULL, `user_id` int(15) NOT NULL, Quote Link to comment Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Okay cool, could you show the PHP code declaring the '$loc_long', '$loc_lat', '$loc_place' (...) variables. Quote Link to comment Share on other sites More sharing options...
andyd34 Posted September 14, 2009 Author Share Posted September 14, 2009 $loc_long = htmlspecialchars($_POST['$loc_long']); $loc_lat = htmlspecialchars($_POST['$loc_lat']); $loc_place = htmlspecialchars($_POST['$loc_place']); $user_id = htmlspecialchars($_POST['''$loc_desc']); mysql_query("INSERT INTO table_locations (longitude, latitude, place_name, description, user_id) VALUES ('$loc_long', '$loc_lat', '$loc_place', '$loc_desc', '$user_id')"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.