Forum Moderators: coopster

Message Too Old, No Replies

Passing Info to a Database from a Form!

this can`t be happening....

         

dreamcatcher

10:02 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi guys,

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?

coopster

10:39 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



First, try adding a 26th field to your form to see if it returns any data when you loop through your POSTed variables. Then at least you will know if it is an issue with the last field, or the overall POSTed data length.

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].

dreamcatcher

10:51 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the help coopster. The problematic field is about the 6th one. All above is working fine and all below is working fine. I`m actually not using ALL input fields, some are radio buttons for options, but all those work fine and all the other input fields work fine. I just can`t understand what the problem is here, its got me stumped big time.

:(

(Thanks for the info about the string literal array, I have changed those now to include quotes)

danieljean

11:16 pm on Dec 5, 2003 (gmt 0)

10+ Year Member



hey, what happens when you do this?

reset ($_POST);
while (list ($key, $val) = each ($_POST))
{
echo "$key => $val<br />\n";
}

dreamcatcher

11:42 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi danieljean,

I ran the code you posted and everything has a value except the one input field, which is the same as when I echoed them all. There is nothing being passed from the one input field. All the other input fields above and below have values.

Strange.

ergophobe

4:26 pm on Dec 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When you say you've echoed the fields, I gather you mean to make sure that $row['s_path'] has the expected value, or do you mean the returned $_POST values?

Have you grepped for possible spelling errors? In other words, you could grep for all occurrences of $_POST[.*] and see what you get.

Tom

dreamcatcher

5:41 pm on Dec 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the info ergophobe. I`ve got it working ok now. I can`t believe the mistake I made and I looked the code over and over. GRRRRR....

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!

danieljean

7:07 pm on Dec 6, 2003 (gmt 0)

10+ Year Member



hi dreamcatcher,

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!

danieljean

7:09 pm on Dec 6, 2003 (gmt 0)

10+ Year Member



hi ergophobe (nice handle, btw ;),

the typo issue was exactly what I was trying to get at: that loop will echo out all the $_POST vars

dreamcatcher

7:13 pm on Dec 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks anyway danieljean. Its all part of the fun in learning.

Yeah right.......:)

ergophobe

8:14 pm on Dec 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




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