Current location: Hot Scripts Forums » Programming Languages » PHP » Updating db with multiple rows


Updating db with multiple rows

Reply
  #1 (permalink)  
Old 07-10-04, 01:46 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Updating db with multiple rows

I have an idea what I am supposed to do but cant think about how !

I am reading the rows from the database; editing if reqiured, changing "N" to "Y" and updating database.

If approve set to "N" ( default form submision form ) it will not be displayed and if set to "Y" it will be - on another page.

PHP Code:

<?php


$query 
"SELECT name, text, approve FROM data WHERE approve ='N'";
$result mysql_query($query);
$num_results mysql_num_rows($result);

echo 
'<form method="POST" action="',$PHP_SELF,'">';

for (
$i=0$i <$num_results$i++)
  {
    
$row mysql_fetch_array($result);

echo 
"<br>Text :<input type='text' name='text",$row[$i],"' size='30' maxlength='255' value ='",$row['text'],"'";
echo 
"<br>Approve :<input type='text' name='approve",$row[$i],"' size='3' maxlength='1' value ='",$row['approve'],"'<br>";
echo 
"<br><input type='hidden' name='name'",$row[$i],";

$update = "UPDATE data SET text $row['text'], approve $row['approve'WHERE name $row[$i]['name']";
$change = mysql_query($update);

}
?>
<br><input type="
submit" name="submit" value="submit">
</form>
What I think should happen is when the data is altered and submit is pressed the data should go into an array and then I need another loop to update the database ?

Can someone point me in the right direction please?

Anthony

Last edited by Bonzo; 07-10-04 at 02:02 PM.
Reply With Quote
  #2 (permalink)  
Old 07-10-04, 05:08 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Loads of typing mistakes in the code !!

Getting closer now; just this error :You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '[0], approve = approve[0] WHERE name = 'name[0]'' at line

I am now posting to another page to update db.

PHP Code:

<?php

        $query 
"SELECT name, text, approve FROM data WHERE approve ='N'";
        
$result mysql_query($query);
        
$num_results mysql_num_rows($result);

echo 
'<form method="POST" action="confirm.php">';

for (
$i=0$i <$num_results$i++)
    {
    
$row mysql_fetch_array($result);

    echo 
"<br>Text : <textarea name='text[]'>",$row['text'],"</textarea>";
    echo 
"<br>Approve :<input type='text' name='approve[]' size='3' maxlength='1' value ='",$row['approve'],"'><br>";
    echo 
"<br><input type='hidden' name='name[]'>";
     }

     echo 
'<br><input type="submit" name="delete" value="submit"></form>';

     
$delete = array();
     
$delete $_POST['delete'];
?>

<?php
 session_start
();

   
$count count($_POST['delete']);
   
   echo 
"count = ",$count;

   for (
$i=0$i<$count$i++)
  {
                  echo 
"<br>",$text[$i]; echo "<br>",$approve[$i]; echo "<br>",$name[$i];

       
$done mysql_query("UPDATE data SET text = text[$i], approve = approve[$i] WHERE name = name[$i]")or die(mysql_error());
     }
?>

Last edited by Bonzo; 07-10-04 at 05:10 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with updating a multiple checkbox form to a MySQL DB jimb575 PHP 1 01-31-06 08:04 PM
stuck on updating multiple records us0r PHP 6 05-20-04 11:19 PM
Help with Multiple DB connections JoJo26 PHP 2 05-07-04 09:27 PM
can't edit multiple rows at the same time conundrum PHP 2 04-01-04 12:50 AM
Deleting multiple rows using radio buttons and text ciggie PHP 2 03-19-04 07:46 PM


All times are GMT -5. The time now is 05:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.