TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-15-2008, 05:01 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default mysql update with multi fields

if i have something like this

Code:
status:  
<select name="status">
<option value="pending">pending</option>
<option value="complete">complete</option>
<option value="declined">declined</option>
</select>

<br>

deadline: <input type="text" name="deadline">

<br>

status: &nbsp;
<select name="status">
<option value="pending">pending</option>
<option value="complete">complete</option>
<option value="declined">declined</option>
</select>

<br>

deadline: <input type="text" name="deadline">

<br>

status: &nbsp;
<select name="status">
<option value="pending">pending</option>
<option value="complete">complete</option>
<option value="declined">declined</option>
</select>

<br>

deadline: <input type="text" name="deadline">

<br>
how do i update each field with mysql update if the table structure looks something like this

Code:
id -- primary key, auto_increment
hash - varchar(100)
status -- varchar(25)
deadline -- date
and the values in this table looks something like this

Code:
id (1)
hash (90j23d093209jk309j3)
status (pending)
deadline(10/10/2008)

id (2)
hash (90j23d093209jk309j3)
status (pending)
deadline(10/10/2008)

id (3)
hash (90j23d093209jk309j3)
status (pending)
deadline(10/10/2008)
just a note the purpose of hash is an md5 or sha1 conversion of the users name to track the users information from table to table. and if i have like 100 people each with a different hash value i can track their information. but the problem i'm having is how do i update the fields if i have being displayed on the page?? u would it it would probably be with the id value but how or where do i display that to track that.??

Code:
this is what the sql update query looks like that im using

$status = mysql_real_escape_string($_POST['status']);
$deadline = mysql_real_escape_string($_POST['deadline'];
$user = $_GET['user']; 
mysql_query("update tbl_userpackage set status = '$status', deadline = '$deadline' where hash = '$user'");
but when i do the update the onyl value that comes in is the last item which is in id 3 all the other stuff doesnt go through
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 02-06-2009, 10:03 PM   #2 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 13
Thanks: 0
trmbne2000 is on a distinguished road
Default

The way I read this is that you have the 3 records, and a form where you want to be able to update the status for all three at the same time? You would need to give each input element a unique name that allows you to figure out which record it goes with.
Make your form like this:
HTML Code:
<select name="status[]">...</select>
<input type="text" name="deadline[]" />
<input type="hidden" name="ids[]" value = "1" />
<select name="status[]">...</select>
<input type="text" name="deadline[]" />
<input type="hidden" name="ids[]" value = "2" />
<select name="status[]">...</select>
<input type="text" name="deadline[]" />
<input type="hidden" name="ids[]" value = "3" />
This will create an array of the statuses, deadlines and row IDs. In your php, then use this:
Code:
for (i=0;i<count($_POST['status']);i++){
    $status = mysql_real_escape_string($_POST['status'][$i]);
    $deadline = mysql_real_escape_string($_POST['deadline'][$i];
    $user = $_GET['user']; 
    $id = floatval($_POST['ids'][$i]);
    mysql_query("update tbl_userpackage set status = '$status', deadline = '$deadline' where hash = '$user' AND id = $id");
}
--Andrew
trmbne2000 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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


All times are GMT. The time now is 07:48 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design