Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 5th, 2005, 03:45 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Manipulating the data in db

I have a check box that when checked and submitted i would like it to change the complete field in my db from 0 to 1. this is my script and php code...

if (isset($_POST['remove']) && isset($_POST['complete']) && is_array($_POST['complete']))
    {
        foreach ($_POST['complete'] as $complete)
        {
            if (!mysql_query("UPDATE orders SET complete=1"))
             {
                echo error_message(sql_error());
            }
        }
    }
    else
    {
        echo "<p align=center> Erorr, Please choose a record to delete!</p><br />\n";
    }

my input box is

" <td><input type='checkbox' name='complete[]' value='{$row['complete']}'>Complete</input></td>\n".

when I check one of the box and submit it, it changes every record in my db to 1... What am i doing wrong?

thanks...
Dungey
Reply With Quote
  #2 (permalink)  
Old January 5th, 2005, 08:39 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

just looking off the top of my head, change the name value to complete without the "[]"


Reply With Quote
  #3 (permalink)  
Old January 5th, 2005, 08:43 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

backtracking here a bit,

when you say "update orders set complete="1"" obviously will change all the fields unless you put a "where" clause there.
so something like:

UPDATE orders set complete=1 WHERE order_id=40;

will only change the row with the order_id that is equal to 40 and not every row.


Reply With Quote
  #4 (permalink)  
Old January 6th, 2005, 12:42 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gotaka4,

Actually, the [] for the complete is the array because in the page i orignally bring up all the records WHERE complete = 0, so immediately each record is 0 when ordered, and will become when when the checkbox is checked and submitted, than the COMPLETE will become 1 and will no longer display on the page, because i am pulling every record WHERE complete = 0...


So the update orders set complete="1" is really updating that particular record and setting the complete to 1, so how do i fix that problem where it only updates one particular record out of 20 that are being pulled?

greatly appreciate you help...
DUNGEY
Reply With Quote
  #5 (permalink)  
Old January 6th, 2005, 11:31 AM
Authorized User
 
Join Date: Dec 2004
Location: Tunkhannock, PA, USA.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

as Gotaka4 pointed out you need a WHERE clause. Regardless of what records you pulled to display (with an initial WHERE of completed=0) the database does not KNOW that you only pulled XX number of rows to display.

So..... You need to qualify your UPDATE statement with a WHERE clause with a specific WHERE clause such as UPDATE orders set complete=1 WHERE order_id=40; (again as Gotaka4 suggests). So maybe on the submit, you have a HIDDEN field to pass the order numbers that you want to change to complete.

Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Manipulating Data with Expressions baaul Reporting Services 2 June 22nd, 2006 10:14 AM
Manipulating Data Problem - - - - Please Help! sendoh11 ASP.NET 1.0 and 1.1 Professional 1 June 29th, 2005 02:40 AM
manipulating data in DAO jimmy Access VBA 2 November 19th, 2003 10:55 AM
Manipulating recordset from the DB sri2004 Classic ASP Databases 1 June 18th, 2003 06:59 AM
Manipulating data in ASP sri2004 Classic ASP Databases 0 June 17th, 2003 07:19 PM



All times are GMT -4. The time now is 12:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.