PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers 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 10th, 2002, 03:00 PM
merrick merrick is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 merrick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
"Insert into" problem

Hello, I'm a newbie hoping that anyone reading this may be willing to
help me with my problem. I'm making a database where my dad can store
his records.
I'm using a form with several sets of radio buttons, one for each
record.
To achieve this I've named each array with a counter, so the first
button set is $kat0[0], set 2 is $kat1[0] and so on.
I'm using the following code with a for loop to insert:

for ($counter=0; $counter< $countrecs; $counter++) {

INSERT INTO recs (id, kat) VALUES (NULL, '$kat$counter[0]')
}

But php refuses to read '$kat$counter[0]' as '$kat0[0]', as I want it
to, instead it looks for $kat, then $counter[0] so I end up with 0[0]
inserted into the database instead of the *real* variable from the
form. I have tried using concatenation, still doesn't work because
then php sees '$kat0[0]' as a STRING and simply inserts "$kat0[0]"
into the database.
How should I solve this? Any help would be very appreciated. Thank you
for reading.

L.

Reply With Quote
  #2  
Old August 10th, 2002, 06:18 PM
cjrobs cjrobs is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Southampton, England
Posts: 121 cjrobs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to cjrobs
RE:

you could try
php Code:
Original - php Code
  1.  
  2. for ($counter=0; $counter< $countrecs; $counter++) {
  3.  
  4. eval('$katcounter = '.$kat . $counter.';');
  5.  
  6. mysql_query("INSERT INTO recs (id, kat) VALUES (NULL, '$katcounter[0]');");
  7. }

Reply With Quote
  #3  
Old August 11th, 2002, 10:32 AM
merrick merrick is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 merrick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE:

Thanks I'll try that!

Reply With Quote
  #4  
Old August 11th, 2002, 02:03 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
RE:

The string variable idea was very close to working

if you have a string, '$kat0[0]' and want php to interpret it as a variable, you need to reference it via a holding variable with two dollar signs... like so:
php Code:
Original - php Code
  1.  
  2. <?php
  3. for($counter=0;$counter<$countrecs;$counter++){
  4.   //create a string representation of the var
  5.   $varname='$kat'.$counter.'[0]';
  6.   //now make php use the string as a variable name reference
  7.   echo $$varname;
  8. }
  9. ?>

Cheers,
Keith.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > "Insert into" problem


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