Page: Previous  1, 2

erikZ
Status: Contributor
Joined: 30 May 2004
Posts: 148
Reply Quote
It's very hard to say for sure with this code sample. Possible errors are something like this:

:: Quote ::
Inserting NULL into a column that has been declared NOT NULL.mysql.com

But it's not possible to say what's going wrong. To me it looks like you are doing this in a way far more complicated than it needs to be. Which makes any problems that much harder to fix.

Basically what you have to do is output the contents of the database after each test insertion to see what is actually happening.

It may just be how you are accessing it, or trying to access it. My first guess, however, is that you are inserting the same dependentID value each time, which means that a column that is supposed to be a unique key is not in fact unique. So when you request a row, you only get one row returned, the first one mysql finds, the first one that was made.

That's my guess anyway. It's easy to test that by simply echoing the value of $i on each insertion to see what it actually is, echo it before the for loop, and then echo it at the insertion point. That's php echo that is. It's always good to use echo to see what data is actually being used, sometimes it's not what you think it will be.
Back to top
ace04
Status: Curious
Joined: 31 Jan 2006
Posts: 9
Location: philippines
Reply Quote
then what should i do?.. frm the first time that i execute that code it actually saves the data in mysql..how do i know?by typing from the command prompt like "select".. and i saw my data there..
Back to top
erikZ
Status: Contributor
Joined: 30 May 2004
Posts: 148
Reply Quote
:: Quote ::
by typing from the command prompt like "select".. and i saw my data there..

Do you mean that all your data is present in the database? But you can't get it out?

What is the value for the index variable, dependentID when you look at the database from the command prompt after doing a few trial insertions?

Again, my guess is that you are doing something wrong with the loop counter and it's simply not creating the unique id you are trying to create, so when you try extracting data using that dependentID value the db just gives the first value.
Back to top
how to retain values in my textboxes??....
ace04
Status: Curious
Joined: 31 Jan 2006
Posts: 9
Location: philippines
Reply Quote
i want to retain what i have inserted in these textboxes... i made use of echo"<td><input type='text' name='banks[$i]' id='banks[$i]' size='15' value=<? echo $bbanks; ?>></td>"; but it still doesnt retained in the form... here's my code...

:: Code ::
<?
$bbanks = $_POST["banks"];
$kkind = $_POST["kind"];
for($r=0; $r<count($liability); $r++)
{
for($i=0;$i<10;$i++)
{
switch($r)
{
case 0:
echo"<td><input type='text' name='banks[$i]' id='banks[$i]' size='15' ></td>";
break;
case 1:
echo"<td><input type='text' name='kind[$i]' id='kind[$i]' size='15'></td>";
break;
}
}
}
?>

Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Two things I don't understand:

1: kind[$i], what kind of variable is that?

2: if you want the form element to print out the value, you have to use the 'value="some value" part too.

So say you have now:

:: Code ::
echo"<td><input type='text' name='kind[$i]' id='kind[$i]' size='15'></td>";
/// this would change to:
echo"<td><input type='text' name='kind[$i]' id='kind[$i]' size='15' value='kind[$i]'></td>";

Which would then show the value data to the user. I'm not sure if that's what you're asking, it's pretty hard to tell from your sample.

What is the physical html that your script output now? Look at the HTML and paste it in here and you'll see pretty easily what's wrong.
Back to top
ace04
Status: Curious
Joined: 31 Jan 2006
Posts: 9
Location: philippines
Reply Quote
this form is asking for information about a liabilities of an applicant and that '$kind' means asking for what kind of liabilities an applicant has. an applicant can have many liabilities that's y i used array.. now i want to retain the value an applicant fills for that textboxes..
i mean like when i'm asking the name of an applicant i just used the value = <?echo $_POST["$fname"]?>; and the value is still in there.. but when i'm using the same in my textboxes which is in an array it doesnt shows anything.. i used like this...

echo"<td><input type='text' name='kind[$i]' id='kind[$i]' size='15' <?echo $_POST["kind[$i"]?> ></td>";
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
sorry, I can't follow you at all, nothing you say makes me able to understand the problem. Have you ever done any programming before? To me it looks like you're just completely guessing at random what to do next. When you are asked to show the html output, that's what you need to do. Restating the same thing again with no relevant code, and not answering the actual questions you're asked doesn't get either you or me anywhere.

Try learning some more on what you need to do, that's the only advice i can give you. It takes time to learn this stuff, but at some point you have to do the work to learn it. Good luck.

I'm closing this topic because it's not going to do anyone in the world any good to try to follow it.
Back to top
Display posts from previous:   
Page: Previous  1, 2
All times are GMT - 8 Hours