User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,052 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,454 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 289 | Replies: 2
Reply
Join Date: Jun 2008
Posts: 3
Reputation: daveg8 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
daveg8 daveg8 is offline Offline
Newbie Poster

column as variable with sql update

  #1  
Jul 19th, 2008
Hi,
I'm struggling to update my table with columns that are identified through variables. For example, I want to update Day3 using the hidden field "NewDay." Eventually, all of my days will be set using hidden field variable. Right now the trouble seems to be the statement %s=%s. Any suggests how to make the column defined by a variable. Thank you in advance. -Dave
$updateSQL = sprintf("UPDATE schedule SET Day1=%s, Day2=%s, %s=%s, Day4=%s, Day5=%s, Day6=%s, Day7=%s, Day8=%s, Day9=%s, Day10=%s, Day11=%s, Day12=%s, Day13=%s, Day14=%s, Day15=%s, Day16=%s, Day17=%s, Day18=%s, Day19=%s, Day20=%s, Day21=%s, Day22=%s, Day23=%s, Day24=%s, Day25=%s, Day26=%s, Day27=%s, Day28=%s, Day29=%s, Day30=%s, Day31=%s, Day32=%s, Day33=%s, Day34=%s, Day35=%s, Day36=%s, Day37=%s, Day38=%s, Day39=%s, Day40=%s, Day41=%s, Day42=%s WHERE UserID=%s",
                       GetSQLValueString($_POST['RadioGroup1'], "text"),
                       GetSQLValueString($_POST['RadioGroup2'], "text"),
                       GetSQLValueString($_POST['NewDay'], "text"),					   
                       GetSQLValueString($_POST['RadioGroup3'], "text"),
                       GetSQLValueString($_POST['RadioGroup4'], "text"),
                       GetSQLValueString($_POST['RadioGroup5'], "text"),
                       GetSQLValueString($_POST['RadioGroup6'], "text"),
                       GetSQLValueString($_POST['RadioGroup7'], "text"),
                       GetSQLValueString($_POST['RadioGroup8'], "text"),
                       GetSQLValueString($_POST['RadioGroup9'], "text"),
                       GetSQLValueString($_POST['RadioGroup10'], "text"),
                       GetSQLValueString($_POST['RadioGroup11'], "text"),
                       GetSQLValueString($_POST['RadioGroup12'], "text"),
                       GetSQLValueString($_POST['RadioGroup13'], "text"),
                       GetSQLValueString($_POST['RadioGroup14'], "text"),
                       GetSQLValueString($_POST['RadioGroup15'], "text"),
                       GetSQLValueString($_POST['RadioGroup16'], "text"),
                       GetSQLValueString($_POST['RadioGroup17'], "text"),
                       GetSQLValueString($_POST['RadioGroup18'], "text"),
                       GetSQLValueString($_POST['RadioGroup19'], "text"),
                       GetSQLValueString($_POST['RadioGroup20'], "text"),
                       GetSQLValueString($_POST['RadioGroup21'], "text"),
                       GetSQLValueString($_POST['RadioGroup22'], "text"),
                       GetSQLValueString($_POST['RadioGroup23'], "text"),
                       GetSQLValueString($_POST['RadioGroup24'], "text"),
                       GetSQLValueString($_POST['RadioGroup25'], "text"),
                       GetSQLValueString($_POST['RadioGroup26'], "text"),
                       GetSQLValueString($_POST['RadioGroup27'], "text"),
                       GetSQLValueString($_POST['RadioGroup28'], "text"),
                       GetSQLValueString($_POST['RadioGroup29'], "text"),
                       GetSQLValueString($_POST['RadioGroup30'], "text"),
                       GetSQLValueString($_POST['RadioGroup31'], "text"),
                       GetSQLValueString($_POST['RadioGroup32'], "text"),
                       GetSQLValueString($_POST['RadioGroup33'], "text"),
                       GetSQLValueString($_POST['RadioGroup34'], "text"),
                       GetSQLValueString($_POST['RadioGroup35'], "text"),
                       GetSQLValueString($_POST['RadioGroup36'], "text"),
                       GetSQLValueString($_POST['RadioGroup37'], "text"),
                       GetSQLValueString($_POST['RadioGroup38'], "text"),
                       GetSQLValueString($_POST['RadioGroup39'], "text"),
                       GetSQLValueString($_POST['RadioGroup40'], "text"),
                       GetSQLValueString($_POST['RadioGroup41'], "text"),
                       GetSQLValueString($_POST['RadioGroup42'], "text"),
                       GetSQLValueString($_POST['UserID'], "int"));

  mysql_select_db($database_connJobvid, $connJobvid);
  $Result1 = mysql_query($updateSQL, $connJobvid) or die(mysql_error());
Last edited by Tekmaven : Jul 19th, 2008 at 2:42 am. Reason: Code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Location: Tulsa
Posts: 52
Reputation: khess is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
Staff Writer
Featured Blogger
khess's Avatar
khess khess is offline Offline
Junior Poster in Training

Re: column as variable with sql update

  #2  
Jul 19th, 2008
Use a regular variable like you would anywhere else. you can't use an expression like that in a sql statement. If it needs to be set to some starting value, do that above the sql statement then just use the variable in the statement.
Ken Hess
Linux Blogger/Columnist
Reply With Quote  
Join Date: Jun 2008
Posts: 3
Reputation: daveg8 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
daveg8 daveg8 is offline Offline
Newbie Poster

Re: column as variable with sql update

  #3  
Jul 19th, 2008
thanks a lot for the help!
I've got it working now.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC