Solved

Inserting updated values in mysql database

Posted on 2012-12-20
5
322 Views
Last Modified: 2012-12-21
Hello Experts,

I am displaying the query results like below on php page....
From mysql there were two rows resulted which is displaying as per the code below...
echo "<tr class=\"d" . ($i & 1) . "\">
                        <td><input class=textboxa type=text style=\"font-style: Italic;font-weight: bold;\" value=\"$i\" /><br/></td>
                        <td><input name=test_$i class=textboxc type=text style=\"font-style: Italic;font-weight: bold;\" value=\"" . $row['Delivery'] . "\" title=Delivery /><br/></td>
                        <td><input name=subtest_$i class=textboxc type=text style=\"font-style: Italic;font-weight: bold;\" value=\"" . $row['quality'] . "\" title=quality /><br/></td></tr>";

Open in new window


If user updates the value in one of the input type text...i would like to updated that value in database.

Can you suggest how to updates the values in mysql where $_POST['test'] this test will might be test_1 or test_2 and so on...

Thanks,
Shail
0
Comment
Question by:ShaileshShinde
  • 2
  • 2
5 Comments
 
LVL 12

Assisted Solution

by:sivagnanam chandrakanth
sivagnanam chandrakanth earned 67 total points
ID: 38712287
Rather than keeping the variable as test_$i, keep it as keep[$i] as array.. iN that way your variable name will be same and key alone will change..

So in submit handler you can handle as

for($i=0;$i<count($_POST['test']);$i++){
$_POST['test'][$i] will have the value for you
}
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 38712505
Hello Expert,

In php i kept name="test[]" and in the POST

for($i=0;$i<count($_POST['test']);$i++){
$test = $_POST['test'][$i] ;
echo "$test";
}
However, this is throwing an error message as "Notice: Undefined index: test in info_r2b.php on line 1"

Can you suggest what's gone wrong in this?

Thanks,
Shail
0
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 33 total points
ID: 38712558
Hello Shail, you must give a name test[] to all of your inputs in order to make ShaileshShindes solution to work.

echo "<tr class=\"d" . ($i & 1) . "\">
                        <td><input class=textboxa type=text style=\"font-style: Italic;font-weight: bold;\" value=\"$i\" /><br/></td>
                        <td><input name=test[] class=textboxc type=text style=\"font-style: Italic;font-weight: bold;\" value=\"" . $row['Delivery'] . "\" title=Delivery /><br/></td>
                        <td><input name=test[] class=textboxc type=text style=\"font-style: Italic;font-weight: bold;\" value=\"" . $row['quality'] . "\" title=quality /><br/></td></tr>";

Open in new window



Althought I've seen this tequnique only with checkboxes.
0
 
LVL 12

Accepted Solution

by:
sivagnanam chandrakanth earned 67 total points
ID: 38712564
@ mcnute is right, except it will for all input types
0
 
LVL 1

Author Closing Comment

by:ShaileshShinde
ID: 38712578
Thanks Experts
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now