fran Posted May 12, 2011 Share Posted May 12, 2011 I have ran this code before and it worked but not it won't update. Can anyone see what I am doing wrong? <? if(isset($_POST[sort_invest])) { // if form was submitted $id = $_POST['sel_record']; $sort = $_POST['sort']; for($i=0;$i<$count;$i++){ $sql = "UPDATE invest SET id='$id[$i]', sort='$sort[$i]' WHERE id='$id[$i]'"; $sql_result = mysql_query($sql,$con) or die (mysql_error()); } } // if form was submitted or if it came from another page if (isset($_POST['order_invest']) || isset($_POST['sort_invest'])) { ?> <p><strong>Order Invest</strong></p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <? $sql = "SELECT id, sort, title FROM invest ORDER BY sort ASC"; $sql_result = mysql_query($sql,$con) or die(mysql_error()); while ($row = mysql_fetch_array($sql_result)) { $id = $row["id"]; $title = $row["title"]; $sort = $row["sort"]; ?> <input type="hidden" name="sel_record[]" value="<? echo "$row[id]"; ?>"> <table width="545" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="69"><input type="text" name="sort[]" value="<? echo "$row[sort]"; ?>" size="3"></td> <td width="476"><? echo "$row[title]"; ?></td> </tr> </table> <br> <? } } ?> <input name="sort_invest" type="submit" value="Sort"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/236239-update-multiple-rows/ Share on other sites More sharing options...
fran Posted May 12, 2011 Author Share Posted May 12, 2011 So many views...No answer??? Quote Link to comment https://forums.phpfreaks.com/topic/236239-update-multiple-rows/#findComment-1214660 Share on other sites More sharing options...
cssfreakie Posted May 12, 2011 Share Posted May 12, 2011 what errors do you get? Does anything happen at all? you may want to add: error_reporting(E_ALL); ini_set("display_errors", 1); above your script. Also are the table names the same as you use them in your query and are the values as expected? Quote Link to comment https://forums.phpfreaks.com/topic/236239-update-multiple-rows/#findComment-1214662 Share on other sites More sharing options...
Maq Posted May 12, 2011 Share Posted May 12, 2011 What have you done to debug this? Echo values out to make sure they're correct. See how far the script gets. As cssfreakie mentioned, temporarily turn on error_reporting. Something must have changed.... So many views...No answer??? Maybe it's b/c you simply said, "My script is broke, someone else fix it". Quote Link to comment https://forums.phpfreaks.com/topic/236239-update-multiple-rows/#findComment-1214663 Share on other sites More sharing options...
fran Posted May 12, 2011 Author Share Posted May 12, 2011 I have gotten my script this far, and as I said...it worked before so I just don't see where I am going wrong. The fields are all correct. I even ran the script with one update and it worked. The problem is when I run it trying to update multiple, it doesn't change anything. I ran the error_reporting(E_ALL); ini_set("display_errors", 1); with no errors showing up. I have scoured over the blogs and cannot find the error of my ways. In answer to "My script is broke, someone else fix it"...I didn't mean to come across that way. I just need a little help finding an error. Quote Link to comment https://forums.phpfreaks.com/topic/236239-update-multiple-rows/#findComment-1214677 Share on other sites More sharing options...
fran Posted May 13, 2011 Author Share Posted May 13, 2011 After spending a lot of time rearranging, changing, testing and researching, I finally got it. Good luck to all who were looking for the answer. I hope this helps. $id = $_POST['sel_record']; $sort = $_POST['sort']; for($i=0;$i<count($id);$i++){ $sql = "UPDATE invest SET sort='$sort[$i]' WHERE id='$id[$i]'"; $sql_result = mysql_query($sql,$con) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/236239-update-multiple-rows/#findComment-1214915 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.