Drummin Posted February 28, 2012 Share Posted February 28, 2012 If you really want to do only ONE UPDATE, Zane already posted code to make that happen. All you were missing was filtering out your record_id and action posts. Because you have not shown us your form or your table fields we can only assume table fields match. <?php if(isset($_POST['action']) && $_POST['action']=="submitform"){ //recieve the variables $roastturkey = $_POST['roastturkey']; $broccoli = $_POST['broccoli']; $brisket = $_POST['brisket']; $carrots = $_POST['carrots']; if(isset($_POST['record_id']) && !empty($_POST['record_id'])){ $record_id=$_POST['record_id']; $myUpdateList = array(); foreach($_POST as $indexName => $value){ if ($indexName!="record_id" && $indexName!="action"){ $myUpdateList[] = "$indexName='$value'"; }//if ($indexName!="record_id" && $indexName!="action") }//foreach($_POST as $indexName => $value) $fields = implode(",", $myUpdateList); $sql=("UPDATE testtable SET $fields WHERE id=$record_id"); $result=mysql_query($sql); }//if(isset($_POST['record_id']) && !empty($_POST['record_id'])) }//if(isset($_POST['action']) && $_POST['action']=="submitform") ?> Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1321936 Share on other sites More sharing options...
Drummin Posted February 28, 2012 Share Posted February 28, 2012 Quote from Zane 4.) I'll bet you all of my life savings that your query failed because you used every single element in your POST array Listen to what people tell you and posting relevant code i.e. the form at least on the first post can spot problems. Both versions I posted should work but make sure you use the IF statement I added to filter out any POST values you are not updating in the DB table. The only two I can see is "action", which I assume is your submit button and the record_id. If there are others add them to this line. if ($indexName!="record_id" && $indexName!="action") //etc Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1321945 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 Good morning everyone! OKAY, let's sort of forget the aforementioned pages for a minute, because they seem to be working (kind of). Here's the issue: My form is created by this code if(mysql_num_rows($query) > 0){ while($row = mysql_fetch_assoc($query)) { $record_id = $row['ID']; echo '<option value="' . $record_id . '">' . $record_id . '</option>'; }} which gives me a dropdown of ALL my id's by row, and renames them $record_id This takes me to a page that carries that record_id and displays a form with values as inputs that can be changed. If there are UPDATES made, then hitting the submit button goes to another php script (shown previously) that should make the update and offer a Success message." My problem here is that updates are NOT occurring, and I am recieving a scripted ERROR message. Apparently my $record_id is NOT being forwarded beyond the first instance. How do I bring it to this second file? Should I be using SESSION, or is a hidden file in order? And where shall it be placed? Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322347 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 Make sure your form on the update page has the input for record_id. <input type="hidden" name="record_id" value="$record_id" /> Echo out the $sql line used for the update on this page to make sure it's as you expect. echo "$sql"; Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322360 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 the first page has this code to display the fields: connect: $result = mysql_query("SELECT * FROM pass WHERE id = $record_id ") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo echo echo submit button the second file that gets called AFTER submission of UPDATES is: if(isset($_POST['action']) && $_POST['action'] == 'submitform') { $roastturkey = $_POST['roastturkey']; $broccoli = $_POST['broccoli']; $brisket = $_POST['brisket']; $carrots = $_POST['carrots']; } $pass = array();foreach($_POST as $indexName => $value) { $pass[] = "$indexName = \"$value\"";} $fields = implode(",", $pass); $sql=("UPDATE pass SET $fields WHERE id = $record_id $result=mysql_query($sql); "); if($result){ echo "Successful"; else { echo "ERROR"; } so where exactly shall i put new code?? Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322369 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 Well you need to be passing your record_id from your first form to the second, which I believe you said you were doing. Not seeing the actual code I can't be sure. This takes me to a page that carries that record_id and displays a form with values as inputs that can be changed. On the second page you grab this posted record_id and make your update based on this id. Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322376 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 ALL the code is posted at bottom of this page 2 Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322378 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 I'm unable to get from page 2 to page 3 with a SUCCESSful UPDATING of the DB Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322382 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 ALL the code is posted at bottom of this page 2 Not really. You're explaining the code not showing code, for example I don't actual show form tags or the actual input tags used. But assuming the record id is being passed to the second form where values can be changed, again not seeing actual code, you convert the posted id to variable to use in a hidden input for your second form. Again I don't know if you are echoing your form or it's written in html, so here a php example. <?php $record_id=$_POST['record_id']; echo "<input type=\"hidden\" name=\"record_id\" value=\"$record_id\" />"; ?> This second form is then posted again and so once again you need to pick up the id before making the update. $record_id=$_POST['record_id']; Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322383 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 Evidently you're assuming that I understand certain things that i do NOT know, and I'm making the same mistake with you. I am trying to save a little room in the thread, but apparently that is backfiring too. Page 1 is a dropdown that sorts the ID's to become $record_id (code on previous page) works fine. Page 2 displays the form with inputs that can be changed (also displays okay) CONNECT $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; if(!empty($record_id)) { $result = mysql_query("SELECT * FROM pass WHERE id = $record_id ") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo "<FORM name='orderpage' action='myupdatepage.php' method='post'>"; echo "<tr><td>"; echo "<select name='roastturkey'>"; echo "<option value='0.00' " . ($row['roastturkey'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['roastturkey'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['roastturkey'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['roastturkey'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['roastturkey'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['roastturkey'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['roastturkey'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['roastturkey'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['roastturkey'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['roastturkey'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['roastturkey'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td rowspan='2'>ROAST TURKEY</span></td><td rowspan='2'>7.00 LB</span></td> "; echo " <td rowspan='2'>ujiujjpooj</span></td><td rowspan='2'> <!-- FILLER --> </span></td>"; echo " <td> <!-- BLANK CELL --> </td><td>STEAMED VEGETABLES</td><td>16.00 LB</td><td>ujiujjpooj</td>"; echo "</tr>"; echo "<tr><td> <!-- FILLER for SPAN--> </td>"; echo " <td>"; echo " <select name='broccoli'>"; echo "<option value='0.00' " . ($row['broccoli'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['broccoli'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['broccoli'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['broccoli'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['broccoli'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['broccoli'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['broccoli'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['broccoli'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['broccoli'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['broccoli'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['broccoli'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td> BROCCOLI</td><td> <!-- NO PRICE HERE --> </td><td>ujiujjpooj</td>"; echo "</tr>"; echo "<tr><td>"; echo " <select name='brisket'>"; echo "<option value='0.00' " . ($row['brisket'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['brisket'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['brisket'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['brisket'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['brisket'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['brisket'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['brisket'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['brisket'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['brisket'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['brisket'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['brisket'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td>BRISKET OF BEEF</td><td>32.00 LB</td><td>ujiujjpooj</td><td> <!-- FILLER --> </td>"; echo " <td>"; echo " <select name='carrots'>"; echo "<option value='0.00' " . ($row['carrots'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['carrots'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['carrots'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['carrots'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['carrots'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['carrots'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['carrots'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['carrots'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['carrots'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['carrots'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['carrots'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td>CARROTS</td><td> <!-- NO PRICE HERE --> </td><td>ujiujjpooj</td>"; echo "</tr>"; <td><input type='submit' name='submitpass' value='Submit Order'> Now, if anything is to be UPDATED, the changes would have been made and when submitted to myupdatepage.php I would get a SUCCESS, not ERROR CONNECT $roastturkey = $_POST['roastturkey']; $broccoli = $_POST['broccoli']; $brisket = $_POST['brisket']; $carrots = $_POST['carrots']; $mytabletest = array();foreach($_POST as $indexName => $value) { $mytabletest[] = "$indexName = \"$value\"";} $fields = implode(",", $mytabletest); $sql=("UPDATE mytabletest SET $fields WHERE id = $record_id "); if($result){ echo "Successful"; } else { echo "ERROR"; } I need to know what to add, and WHERE to place it. Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322390 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 Within your second form add echo "<input type=\"hidden\" name=\"record_id\" value=\"$record_id\" />"; On your final processing page add $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322392 Share on other sites More sharing options...
KevinM1 Posted February 29, 2012 Share Posted February 29, 2012 @phppup - In the future, please place all of your code in either or tags. I took the liberty of doing it for you above. Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322395 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 Am i adding anyplace specific, because when I put it where I thought it should go, I still get the same failure ERROR. Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322398 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 The hidden input tag can go anywhere within the form. I added it after your form tag. I do see however that you are wrapping your form around <tr> tags. This is NOT good but that's another issue. Get yourself TIDY HTML validator for Firefox. $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; if(!empty($record_id)) { $result = mysql_query("SELECT * FROM pass WHERE id = $record_id ") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo "<FORM name='orderpage' action='myupdatepage.php' method='post'>"; echo "<input type=\"hidden\" name=\"record_id\" value=\"$record_id\" />"; echo "<tr><td>"; echo "<select name='roastturkey'>"; echo "<option value='0.00' " . ($row['roastturkey'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['roastturkey'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['roastturkey'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['roastturkey'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['roastturkey'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['roastturkey'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['roastturkey'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['roastturkey'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['roastturkey'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['roastturkey'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['roastturkey'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td rowspan='2'>ROAST TURKEY</span></td><td rowspan='2'>7.00 LB</span></td> "; echo " <td rowspan='2'>ujiujjpooj</span></td><td rowspan='2'> <!-- FILLER --> </span></td>"; echo " <td> <!-- BLANK CELL --> </td><td>STEAMED VEGETABLES</td><td>16.00 LB</td><td>ujiujjpooj</td>"; echo "</tr>"; echo "<tr><td> <!-- FILLER for SPAN--> </td>"; echo " <td>"; echo " <select name='broccoli'>"; echo "<option value='0.00' " . ($row['broccoli'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['broccoli'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['broccoli'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['broccoli'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['broccoli'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['broccoli'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['broccoli'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['broccoli'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['broccoli'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['broccoli'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['broccoli'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td> BROCCOLI</td><td> <!-- NO PRICE HERE --> </td><td>ujiujjpooj</td>"; echo "</tr>"; echo "<tr><td>"; echo " <select name='brisket'>"; echo "<option value='0.00' " . ($row['brisket'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['brisket'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['brisket'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['brisket'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['brisket'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['brisket'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['brisket'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['brisket'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['brisket'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['brisket'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['brisket'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td>BRISKET OF BEEF</td><td>32.00 LB</td><td>ujiujjpooj</td><td> <!-- FILLER --> </td>"; echo " <td>"; echo " <select name='carrots'>"; echo "<option value='0.00' " . ($row['carrots'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['carrots'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['carrots'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['carrots'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['carrots'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['carrots'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['carrots'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['carrots'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['carrots'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['carrots'] == 9.00 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($row['carrots'] == 10.00 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td>CARROTS</td><td> <!-- NO PRICE HERE --> </td><td>ujiujjpooj</td>"; echo "</tr>"; <td><input type='submit' name='submitpass' value='Submit Order'> Again on the final processing grab this id. $record_id = $_POST['record_id']; $roastturkey = $_POST['roastturkey']; $broccoli = $_POST['broccoli']; $brisket = $_POST['brisket']; $carrots = $_POST['carrots']; $mytabletest = array(); foreach($_POST as $indexName => $value) { $mytabletest[] = "$indexName = \"$value\"";} $fields = implode(",", $mytabletest); $sql=("UPDATE mytabletest SET $fields WHERE id = $record_id "); $result=mysql_query($sql); if($result){ echo "Successful"; } else { echo "ERROR"; } Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322401 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 It did NOT work. I commented OUT these lines, and hardcoded the third, and DID get a SUCCESS message: #$pass = array();foreach($_POST as $indexName => $value) { $pass[] = "$indexName = \"$value\"";} #$fields = implode(",", $pass); $sql=("UPDATE pass SET carrots ='6' WHERE id = '5' "); So now what?? Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322416 Share on other sites More sharing options...
Pikachu2000 Posted February 29, 2012 Share Posted February 29, 2012 Have you echoed the query string an inspected it to see what's wrong with it? Have you echoed mysql_error() to see the error returned by the db? Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322419 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 I only get messages from "echo MySQL" when there is success, so I have to assume that there are no messages on failure because there is NO DATA being transferred. The $id_record connection is not being made. :-( Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322421 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 What do you see when using this? <?php if(isset($_POST['action']) && $_POST['action']=="submitform"){ //recieve the variables $roastturkey = $_POST['roastturkey']; $broccoli = $_POST['broccoli']; $brisket = $_POST['brisket']; $carrots = $_POST['carrots']; if(isset($_POST['record_id']) && !empty($_POST['record_id'])){ $record_id=$_POST['record_id']; $myUpdateList = array(); foreach($_POST as $indexName => $value){ if ($indexName!="record_id" && $indexName!="action"){ $myUpdateList[] = "$indexName='$value'"; }//if ($indexName!="record_id" && $indexName!="action") }//foreach($_POST as $indexName => $value) $fields = implode(",", $myUpdateList); echo "$fields"; //$sql=("UPDATE testtable SET $fields WHERE id=$record_id"); //$result=mysql_query($sql); }//if(isset($_POST['record_id']) && !empty($_POST['record_id'])) else{ echo "Record id is missing"; } }//if(isset($_POST['action']) && $_POST['action']=="submitform") ?> Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322424 Share on other sites More sharing options...
Pikachu2000 Posted February 29, 2012 Share Posted February 29, 2012 I ask again, have you echoed the query string and inspected it to see what's wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322425 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 Drum: I used your code in place of mine (with commented areas remaining commented) and got a BLANK screen response. Pikachu: How shall i do that? (please be specific as to where to place code if you provide any) Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322432 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 Add this to the top of your page. echo "<pre>"; print_r($_POST); echo "</pre>"; Do you see [action] => submitform Show the results. Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322434 Share on other sites More sharing options...
Pikachu2000 Posted February 29, 2012 Share Posted February 29, 2012 It's no different than echoing any other variable. You use the echo construct with the variable that holds your query string. Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322437 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 Still runnning your code and I got: Array ( [record_id] => 2 [roastturkey] => 4.00 [broccoli] => 0.00 [brisket] => 0.00 [carrots] => 0.00 [submitpass] => Submit Order ) Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322438 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 Then how is this line supposed to work? if(isset($_POST['action']) && $_POST['action']=="submitform") Change it to if(isset($_POST['submitpass']) && $_POST['submitpass']=="Submit Order") Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322440 Share on other sites More sharing options...
phppup Posted February 29, 2012 Author Share Posted February 29, 2012 okay. still got similar message. There is no success message so I have to assume I'm connecting. Gonna need to check the database directly, but got same messages twice (only variations were from order number and item quantitieis.) Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/2/#findComment-1322441 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.