acctman Posted April 29, 2009 Share Posted April 29, 2009 I'm using an array to hold all the $_post from my Form. Currently I have the form name fields set to something like name=add[city] or name=add[state] etc... I having a conflict with a javascript that doesn't like the [] in the name= so I'd like to change my post array to work without the add[]. how can I do that? Example all name= fields would be name=city, name=state, etc... can I simply just remove ['add'] from my foreach and is_array? if (is_array($_POST['add'])) { foreach ($_POST['add'] as $key => $value) $_POST['add'][$key] = strip_tags(stripslashes($value)); foreach ($_POST['add'] as $key => $value) mysql_query("UPDATE r_members SET m_".$key."='".sql_escape_string(stripslashes($value))."' WHERE m_id=$m_id"); } Link to comment https://forums.phpfreaks.com/topic/156193-_post-array-question/ Share on other sites More sharing options...
Daniel0 Posted April 29, 2009 Share Posted April 29, 2009 Use IDs for selecting using Javascript instead. Link to comment https://forums.phpfreaks.com/topic/156193-_post-array-question/#findComment-822266 Share on other sites More sharing options...
ToonMariner Posted April 29, 2009 Share Posted April 29, 2009 why have you used name="add[]" in your form? unless the inputs are check boxes there is little to be gained from this. give your fieldnames a distinguishable value. also make you code a little more efficient - no point in looping twice NOR having multiple queries... using your current code... <?php if (is_array($_POST['add'])) { $qry = NULL; foreach ($_POST['add'] as $key => $value) { $qry .= "UPDATE r_members SET m_".$key."='".mysql_real_escape_string(stripslashes($value))."' WHERE m_id=$m_id; "; } $res = mysql_query($qry); } ?> Link to comment https://forums.phpfreaks.com/topic/156193-_post-array-question/#findComment-822271 Share on other sites More sharing options...
acctman Posted April 29, 2009 Author Share Posted April 29, 2009 why have you used name="add[]" in your form? unless the inputs are check boxes there is little to be gained from this. give your fieldnames a distinguishable value. also make you code a little more efficient - no point in looping twice NOR having multiple queries... using your current code... <?php if (is_array($_POST['add'])) { $qry = NULL; foreach ($_POST['add'] as $key => $value) { $qry .= "UPDATE r_members SET m_".$key."='".mysql_real_escape_string(stripslashes($value))."' WHERE m_id=$m_id; "; } $res = mysql_query($qry); } ?> i also need to add the following do I just remove name=exp[descr] from my name field and change it to name=descr and check the post from $_POST['exp']['descr'] to $_POST['descr'] ? $allowedTags='<p><strong><em><u><h1><h2><h3><h4><h5><h6><img>'; $allowedTags.='<li><ol><ul><span><div><br><ins><del><hr>'; if($_POST['exp']['descr']!='') { $sContent = strip_tags(stripslashes($_POST['exp']['descr']),$allowedTags); mysql_query("UPDATE r_members SET m_descr='".sql_escape_string(stripslashes($sContent))."' WHERE m_id=$m_id"); } Link to comment https://forums.phpfreaks.com/topic/156193-_post-array-question/#findComment-822279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.