Solved

Inserting updated values in mysql database

Posted on 2012-12-20
5
308 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 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

19 Experts available now in Live!

Get 1:1 Help Now