Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2005, 03:45 PM
Authorized User
 
Join Date: Jun 2003
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
 
Old January 5th, 2005, 08:39 PM
Authorized User
 
Join Date: Jan 2005
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 "[]"


 
Old January 5th, 2005, 08:43 PM
Authorized User
 
Join Date: Jan 2005
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.


 
Old January 6th, 2005, 12:42 AM
Authorized User
 
Join Date: Jun 2003
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
 
Old January 6th, 2005, 11:31 AM
Authorized User
 
Join Date: Dec 2004
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





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





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