Jump to content

mysql_real_escape_string in my array


harkly

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/205577-mysql_real_escape_string-in-my-array/
Share on other sites

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"]);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.