Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2006, 06:20 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default update all rows at the same time, same field, how?

Hi, I have a small problem. I made a form to update serveral id's at the same time. Im looking to update the same field.

PHP Code:
echo "<form action='page.php?action=order' method='POST'>";
$sql "SELECT * FROM `page` ORDER BY `order` DESC";
    
$result mysql_query($sql) or die(mysql_error());
    while (
$row mysql_fetch_object($result))
{
echo 
"<input type='text' name='order' value='$row->order'>";
}
echo 
"<input type='submit' value='save'></form>"
in page.php?action=order:
PHP Code:
$sql "UPDATE `page` SET order = '".$_POST['order']."'";
mysql_query($sql) or die(mysql_error()); 
Im clueless, any suggestions?

Thanks in advance
Niklas
Reply With Quote
  #2  
Old 04-14-2006, 03:50 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

what's the error?
Reply With Quote
  #3  
Old 04-14-2006, 05:10 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

right now there are 4 rows in that table, so the "order" field should be updated 4 times. Once for each row. If I use the above code, all rows get the same value, and I cant put in...
PHP Code:
WHERE `id` = '"$_GET['id']"' 
...since im not looking to update a single row. Im looking to update all rows.

That would be the error i guess...

Any suggestions?

Thanks for taking the time to answer!

/Niklas
Reply With Quote
  #4  
Old 04-14-2006, 06:02 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Without answering the problem, I'll say that you better wrap everything you put in the database with addslashes() lest you want a database injection exploit.
Reply With Quote
  #5  
Old 04-14-2006, 07:55 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you show me what that would look like? Im sorry but I dont understand since this is all new to me.

Thanks
Reply With Quote
  #6  
Old 04-14-2006, 10:55 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

addslashes is crap use mysql_escape_string() http://dev.mysql.com/doc/refman/5.0/...pe-string.html

anyway:
PHP Code:
$sql "UPDATE 'page' SET order = '" $_POST['order'] . "' "
that looks right to me, unless you provide an error message, no one can help.
Reply With Quote
  #7  
Old 04-15-2006, 02:44 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It is working, but now the way i want. I want it to work just like when you set the vB forum order. But thats not possible with my strings of code since all text fields have the same "name", and that gives all rows in the db the same value. for example:

<input type="text" name="order" value="1">
<input type="text" name="order" value="2">
<input type="text" name="order" value="3">
<input type="text" name="order" value="4">

once you hit the submit button the value "4" will be put in all rows in the database. instead of that, i want "1" to be put in the first row, "2" to be put in the second row and so on.....the question is how...

Thanks!
Reply With Quote
  #8  
Old 04-15-2006, 05:09 PM
Code Monkey's Avatar
Code Monkey Code Monkey is offline
 
Join Date: May 2004
Posts: 1,080
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're creating multiple text fields in that loop and they all have the same name value.
Reply With Quote
  #9  
Old 04-15-2006, 06:23 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes I'm aware of that. Now I'm looking for a solution.....

I tried the following:
PHP Code:
echo "<form action='page.php?action=order' method='POST'>"
$sql "SELECT * FROM `page` ORDER BY `id` DESC"
    
$result mysql_query($sql) or die(mysql_error()); 
    while (
$row mysql_fetch_object($result)) 

echo 
"<input type='text' name='order[$row->id]' value='$row->order'>"

echo 
"<input type='submit' value='save'></form>"
In page.php?action=order:
PHP Code:
    $sql "SELECT * FROM `page` ORDER BY `id` DESC";
    
$result mysql_query($sql) or die(mysql_error());
    while (
$row mysql_fetch_object($result))
    {
        
$insert $_POST["order[$row->id]"];
    
        
$sql "UPDATE `page` SET `order` = '$insert' ORDER BY `id` DESC";
        
mysql_query($sql) or die(mysql_error());
    } 
Sadly, it didnt work. Didnt think it would but it was worth a try atleast. For some reason, the mysql query can only store one value, and tha value is stored in every row.
Reply With Quote
  #10  
Old 04-17-2006, 07:56 PM
error_22 error_22 is offline
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works, thanks for all the help!
Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


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


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04523 seconds
  • Memory Usage 2,264KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete