harkly Posted June 22, 2010 Share Posted June 22, 2010 I have an array of heights and I want to be able to insert into my db the heights in this format - 5'9 I know I need to use the mysql_real_escape_string but I am not sure where. Can someone help me out?? here is my code: while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $height=mysql_real_escape_string($r["height"]); $eye_color=$r["eye_color"]; $hair_color=$r["hair_color"]; $hairColor_othr=$r["hairColor_othr"]; } echo " <div id='aboutLifestyle'> <span class='headerbox'> Height: </span> <span class='textbox'> \n"; $height_arr = array( 1 => '', 2 => '2\'', 21 => '2\' 1', 22 => '2\' 2', 23 => '2\' 3', 24 => '2\' 4', 25 => '2\' 5', 26 => '2\' 6', 68 => '6\' 8', 69 => '6\' 9', 610 => '6\' 10', 611 => '6\' 11', ); $select = '<select name="height" id="st_age" size="1" class="selectOne">'."\r\n"; foreach($height_arr as $key => $value){ $select .= "\t".'<option value="'.$key.'"'.(($key == $height) ? ' selected="selected"' : '').'>'. $value.'</option>'."\r\n"; } $select .= '</select>'; echo $select; echo " </span> Quote Link to comment https://forums.phpfreaks.com/topic/205577-mysql_real_escape_string-in-my-array/ Share on other sites More sharing options...
wildteen88 Posted June 22, 2010 Share Posted June 22, 2010 By looks of things you don't need to use mysql_real_escape_string at all as your form is not submitting the actual height (eg 5'9) but the array key corresponding to the height (eg 59) in the $height_arr array. Also you only need to use mysql_real_escape_string when you're inserting data into the database, not when you're grabbing data from the database. $height=mysql_real_escape_string($r["height"]); Quote Link to comment https://forums.phpfreaks.com/topic/205577-mysql_real_escape_string-in-my-array/#findComment-1075746 Share on other sites More sharing options...
harkly Posted June 22, 2010 Author Share Posted June 22, 2010 Gotcha! THanks! Quote Link to comment https://forums.phpfreaks.com/topic/205577-mysql_real_escape_string-in-my-array/#findComment-1075749 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.