Jump to content

Update multiple rows


fran

Recommended Posts

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.