Jump to content


Photo

Parse errors in insert loop.


  • Please log in to reply
4 replies to this topic

#1 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 20 July 2004 - 06:32 PM

Hi all
I have created an insert loop to increment fieldname by count. $x will define the loop number so I wish to display 'track_name' as ' track_name1', 'track_name2' etc on each cycle of the loop. Trying to parse the $x to the track_name always seems to return a parse error. If anyone can shed some light on how to achieve this I would be grateful.

$insertSQL = sprintf("INSERT INTO metal_tracks (disco_id, track_name, comments) VALUES (%s, %s, %s)", 
                         
          GetSQLValueString($_POST['disco_id'], "int"), 
          GetSQLValueString($_POST['track_name'], "text"), 
          GetSQLValueString($_POST['comment'], "text"));


Thanks in advance for any suggestions.

#2 theverychap

theverychap
  • Staff Alumni
  • Advanced Member
  • 78 posts
  • LocationDevon, England

Posted 20 July 2004 - 06:41 PM

must say i think thats a bit complicated to just insert data with an auto-incrementing number appended to a string, could you post a bit more of the code so i can see whats ging on..?

#3 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 20 July 2004 - 07:04 PM

Heres the full loop and they arent auto incrementing. Disco id is the auto increment field. Its value remains the same in all entries from an echo session. The other 2 fields are to be inserted from a fully dynamic form that could have upto 40 entries. The for is also built from a loop based on a form variable so I need to reverse the loop to insert the fields.

Thanks again.

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
//conditional loop
if (isset($_POST['send'])) 
{ 
$send = $_POST['send']; 
} 
else 
{ 
exit(); 
}  
for ($x = 1; $x <= $send; $x++) 
{

  $insertSQL = sprintf("INSERT INTO metal_tracks (disco_id, track_name, comments) VALUES (%s, %s, %s)",
      
                       GetSQLValueString($_POST['disco_id'], "int"),
                       GetSQLValueString($_POST['track_name'], "text"),
                       GetSQLValueString($_POST['comment'], "text"));
       

  mysql_select_db($database_SiteConn, $SiteConn);
  $Result1 = mysql_query($insertSQL, $SiteConn) or die(mysql_error());
}


#4 theverychap

theverychap
  • Staff Alumni
  • Advanced Member
  • 78 posts
  • LocationDevon, England

Posted 20 July 2004 - 07:28 PM

unfortunately i'm not au-faix with dreamweavers way of outputting php, so unfortunately i wont be able to really help.

just for the record, i used to use dreamweaver a long time ago (before php support) and quickly got tired of its rewriting of my code, so i knocked it on the head)

sorry about that.

im going to move this topic to the Dreamweaver forum...



#5 theverychap

theverychap
  • Staff Alumni
  • Advanced Member
  • 78 posts
  • LocationDevon, England

Posted 20 July 2004 - 07:30 PM

ok, im spun right out now, i wasnt in the dreamweaver forum, i moved the topic, then an error occurred, showed me that i was in the dreamweaver forum, then posted this post twice. how very strange.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users