About
|
|
Author: FR
|
|
Credits:
|
|
|
Brookfresh, Brad Lawryk, Crogon, DaMysterious, EklipzeDesigns, ML, musashi, phpBB Group, phpBB-Auction-Team, php-styles, sanman, Tel, Vampy, wGEric
|
|
Supported Sites
|
|
Statistics
|
User:
|
18760
|
Posts:
|
18401
|
Latest User:
|
MafunaFeept
|
|
|
|
View previous topic :: View next topic |
Author |
Message |
guyb Small-Cap Auctioneer

Joined: 22 Oct 2008 Posts: 21
|
Posted: Tue Oct 13, 2009 7:52 am Post subject: Easy: what code to use to update sql table? |
|
|
A relative easy question that I don't know the answer to: I'm trying to receive data from form fields and upload them into an sql table, but I've seen variations of sql UPDATEs and I don't know which kind to use.
I've seen data received in like this:
Code: | $data_input = $HTTP_POST_VARS['data_input']; |
Or like this:
Code: | $data_input = ( isset($HTTP_POST_VARS['data_input']) ) ? $HTTP_POST_VARS['data_input'] : $HTTP_GET_VARS['data_input']; |
and used to UPDATE sql like this:
Code: | data_input = '" . $data_input . "', |
But I've also seen sql UPDATEd like this:
Code: | forum_status = " . intval($HTTP_POST_VARS['forumstatus']) . ", |
and like this (with ''):
Code: | topic_last_poster_id = '$topic_last_poster_id', |
Or this (without ''):
Code: | session_time = $current_time, |
Can anyone give me some direction as to what goes with what and when? |
|
Back to top |
|
 |
FR Site Admin

Joined: 26 Jan 2004 Posts: 1764 Location: root directory
|
Posted: Wed Oct 14, 2009 4:17 am Post subject: |
|
|
on your first to options:
the first one just works with HTTP POST.. on one of my new servers just the HTTP_GET works. therefore the second query will function with both settings. the first query will just work with POST.
on the UPDATE field
the function intval() transforms the input into an integer value. the first example (Code #3) is for a string or text (thats also the reason you have the '" . $variable . "'
on your last two examples:
The second one (last code example from you) compares values /numbers. you do not need the little ' (do not know the english word) for it. the first one (second last code example) compares a string / text which requires the little '
Hope it helps. _________________ Want to say thank you. Use my Amazon Wishlist
Meet the world on movie-on.com |
|
Back to top |
|
 |
guyb Small-Cap Auctioneer

Joined: 22 Oct 2008 Posts: 21
|
Posted: Fri Oct 16, 2009 8:39 am Post subject: |
|
|
Thanks! That helped me clear up a lot of my sql UPDATE coding.
I have a follow-up question though: I can't get checkbox values to be processed correctly. Originally selected values display fine, but subsequent changes which I UPDATE seem to override any future changes I make.
Working backwards, here's how my 3 checkboxes are assigned to the template:
Code: | 'AUCTION_OFFER_BOLD_CHECKED' => ( $offer_rowset[$i]['auction_offer_bold']) ? "checked=\"checked\"" : "",
'AUCTION_OFFER_ON_TOP_CHECKED' => ( $offer_rowset[$i]['auction_offer_on_top']) ? "checked=\"checked\"" : "",
'AUCTION_OFFER_SPECIAL_CHECKED' => ( $offer_rowset[$i]['auction_offer_special']) ? "checked=\"checked\"" : "",
|
And here are 4 different ways I've tried to receive default or edited values:
1.
Code: | $auction_offer_special = ( isset($HTTP_POST_VARS['offer_special']) ) ? ( ($HTTP_POST_VARS['offer_special']) ? TRUE : 0 ) : $HTTP_GET_VARS['offer_special']; |
2.
Code: | $auction_offer_special = $HTTP_POST_VARS['offer_special']; |
3.
Code: | if (empty($HTTP_POST_VARS['offer_special']) )
{
$auction_offer_special = 0;
}
else
{
$auction_offer_special = 1;
}
|
4.
Code: | $auction_offer_special = ( isset($HTTP_POST_VARS['offer_special']) ) ? intval( $HTTP_POST_VARS['offer_special'] ) : 0; |
My sql UPDATE for them looks like this:
Code: | auction_offer_special = $auction_offer_special,
auction_offer_on_top = $auction_offer_on_top,
auction_offer_bold = $auction_offer_bold
WHERE PK_auction_offer_id ='" . $offer_id . "'"; |
Depending on which of the 4 methods above I use I sometimes get a debugging error regarding returned values of "on". Any ideas which way I'm supposed to code to receive checkbox values?
My customization is based on your existing coding and for these 3 values I noticed in "auction_offer" different references to the variables, like "offer_special" and "auction_offer_special". Am I perhaps supposed to use "auction_offer_special" all the time?
(I fixed an oversight on your "auction_store" pages with the radio buttons which weren't getting updated after selection - there, with yes/no radio buttons I can update intval selections but with intval checkboxes with 0/1 values like above I can't seem to get it) |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|