General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 12th, 2003, 04:47 AM
GreenHornet GreenHornet is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 16 GreenHornet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Problem reiterating column_names for use in subsequent insert query.

I have a query selecting all column names of a table. A form is then created from this.
This step works correctly.
When the form is submitted, however, I cannot get the script to read in the values sent by the user which then match to the column name with which it should insert against. I have been, at various times , able to write the columnnames (prefixed with a dollar sign) back into the database, but not the values submitted by the form.

I have included the meat of it in a txt. Any help is much appreciated.
Attached Files
File Type: txt problem_insert.txt (1.4 KB, 416 views)

Reply With Quote
  #2  
Old August 12th, 2003, 06:58 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Why not just do something like the following:

PHP Code:
 $insert_a=array();
$insert_b=array();

while(list(
$key,$val)=each($_POST)){
    if(
$key != "ID"){ // and any other exceptions
        
array_push($insert_a,$key);
        
array_push($insert_b,addslashes($val));      
    }
}

$sql="INSERT INTO " $table " (" join(",",$insert_a) . ") VALUES ('" join("','",$insert_b) . "')"


I don't see any real advantage to validating your column list against what's actually in the database: Since you're forcing the column list anyway, if anybody screws with the field names and provides invalid columns, the query'll bomb anyway. And it appears that your field names are going to match column names in any case, so you might as well make the task easy on yourself.

Reply With Quote
  #3  
Old August 22nd, 2003, 11:43 AM
GreenHornet GreenHornet is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 16 GreenHornet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks

aah...I'll put it down to minimal array function knowledge (to start with).
Otherwise, thanks for your time - this will definitely save much of mine...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Problem reiterating column_names for use in subsequent insert query.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway