dynamic variables
Posted: Thu Apr 14, 2005 2:08 am
Hi.
I've used PHP for a while for small projects, but I am now working on my first more ambitious project and I am hopelessly stuck. Perhaps somebody could help me out.
In my code, I have this function:
So, when I read the values of a submitted form, I just do
which is all fine and working very well. But, the problem I'm having is that I sometimes have to deal with getting the value from form inputs which are themselves dynamically created and I don't know the input name ahead of time:
X in wordX is the id#, i.e. primary key from the database for the given word. So I really need it to update the record if it has been changed.
SOOOO... What is common practice in situations like this? Is there a regex way to handle this? How do I get something like:
and how do I then separate the X so that I can say:
Or is there an easier way to deal with it? As I said, this is the first time I have encountered this level of complexity. And I'll be most grateful for any tips or references you may have. Even if you say: "hey, dude, you're a complete moron in the first place, whoever heard of <input name = 'word17'>...
All best,
Tench
I've used PHP for a while for small projects, but I am now working on my first more ambitious project and I am hopelessly stuck. Perhaps somebody could help me out.
In my code, I have this function:
Code: Select all
function readvar($name) {
global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;
$temp=$_COOKIE[$name];
if ($_POST[$name]) $temp=$_POST[$name];
if ($_GET[$name]) $temp=$_GET[$name];
$temp=str_replace("\\","\\\\",$temp);
$temp=str_replace("'","\\'",$temp);
return $temp;
}Code: Select all
$new['definition'] = readvar('definition');Code: Select all
<input name = word7 value = "e;dog"e;>
<input name = word185 value = "e;cat"e;>SOOOO... What is common practice in situations like this? Is there a regex way to handle this? How do I get something like:
Code: Select all
$new['wordX'] = readvar('wordX');Code: Select all
q = mysql_query("e;update word set word = '$newї'wordX'] where wordID = 'X'"e;);All best,
Tench