www.webdeveloper.com
Results 1 to 2 of 2

Thread: Array issue...

  1. #1
    Join Date
    Mar 2005
    Posts
    172

    Array issue...

    Evening Guys,

    Wondering if someone could help me with a major headache i'm getting that I can't solve/

    I’m trying to create an array to post multiple values into my database table.

    PHP Code:

    $lastinsert 
    mysql_insert_id(); //to get report_id from reports table

    $sql = array(); 
    foreach(
    $_REQUEST['r'] as $row)
       { 
            
    $sql[] = sprintf("('%s', %d)"
                
    $player_id $row['player_id'],
                
    $team_id $_GET['team_id']);    
        } 
                        
    $query_three mysql_query("INSERT INTO `goals2` ( `player_id`,`team_id`, `report_id` ) 
     VALUES ('
    $sql', '$lastinsert')"); 
    Now I want to get the first two values from the array I created and the $lastinsert value (report_id) from the last insert in another table. However it just outputs the message ‘query is empty’ in my validation checks to see if any data enters the database.

    Anyone see what’s wrong please?

    Thanks

    Chris

  2. #2
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    PHP Code:
    $lastinsert mysql_insert_id(); //to get report_id from reports table

    foreach($_REQUEST['r'] as $row)
    {
        
    mysql_query("INSERT INTO `goals2` ( `player_id`,`team_id`, `report_id` ) VALUES ('".$row['player_id']."', '".(int)$_GET['team_id']."', '".$lastinsert."')");

    Something like that?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles