Solved

Inserting updated values in mysql database

Posted on 2012-12-20
5
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The viewer will learn how to dynamically set the form action using jQuery.
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…

726 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