Forum Moderators: coopster
Good job I`m the patient type, it really is, because this has been doing my head in for the last 2 hours.
Ok, I`m passing info from a form to a database. Now I`ve done this countless times before without any problems, however, this time I`ve hit a slight snag.
I have about 25 input fields, each with a similar syntax, ie:
<input type=\"text\" size=\"30\" name=\"seturlpath\" value=\"" . $row[w_path] . "\">
My form action is:
<form method="POST" action="settings.php?action=update">
Then I`m doing:
if ($_GET['action'] == "update"){
$seturlpath = $_POST['seturlpath'];
and so on...
}
Then I`m adding the info to the database, which is working fine.
Well, except for one input field. It doesn`t matter what I name it, the info is not getting passed to the database. 24 are working fine, the 25th nothing.
I`ve echoed the fields to see if they are returning a value and all are except the one, which is:
<input type=\"text\" size=\"30\" name=\"setserverpath\" value=\"" . $row[s_path] . "\">
I`ve renamed "setserverpath" several times, but still nothing. I`m accessing it the same as the other fields:
$setserverpath = $_POST['setserverpath'];
Like I say, this field is returning nothing at all. I`m doing error checking for blank fields: ie:
if ($setserverpath == "") { echo "Error"; }
But this field just doesn`t work, the others work fine.
This is just NOT possible right?
Any ideas?
P.S. You should always use quotes around a string literal array index [php.net].
For example, use $row['s_path'] and not $row[s_path].
:(
(Thanks for the info about the string literal array, I have changed those now to include quotes)
In the if statement for the blank field checks I had put:
$setserverpath = ""
should have been $setserverpath == ""
This was off screen in my text editor, so maybe thats why I didn`t see it. I`m trying to make excuses for me driving myself insane. I should get out more thats the problem. :)
Thanks for all the help!
This happens to all of us, and you are quite right: you need to get out for a walk ;)
I can't tell you the number of times when I walked over to a colleagues desk, have them explain the problem and... "d'OH!, never mind, I found it". Nor can I count the number of times I've done that!
the typo issue was exactly what I was trying to get at: that loop will echo out all the $_POST vars
Oh yeah. I got caught up in thinking of it echoing out the values, forgetting that it would also echo out the var names.
Anyway, that was just an example, my idea was that you could grep not just of the $_POST but for "set.*path" and ".*serverpath" and "setser.*" so that if somewhere it was being messed up by "seterverpath" you would find it. Also, since it outputs the line of code for each hit, it *might* help ID the single =, though you would have to be looking for it.
hi ergophobe (nice handle, btw ;),
Thanks - I'm quite proud of it usually... every once in a while it can be a bit embarassing but I'm rather attached to it.
Tom