FOR each help.....

Discussion in 'PHP' started by ghadacr, Aug 3, 2007.

  1. #1
    The below for each is not working as its not inserting the code into the database, i'm not sure what to do help please...

    <?PHP include 'opendb.php'; ?>
    
    <?PHP include 'header.php'; ?>
    
    <?php 
    
    $title   = $_GET['title'];
    $firstname  = $_GET['firstname'];
    $surname  = $_GET['surname'];
    $ChildAdult  = $_GET['ChildAdult'];
    $cost  = $_GET['cost'];
    $notes  = $_GET['notes'];
    $flight  = $_GET['flight'];
    $client  = $_GET['client'];
    
    foreach ($_GET as $index => $key) 
    {
    
    $query = mssql_init ("sp_insertFlightSpaces"); 
    
    mssql_bind($query, "@FlightID", $flight, SQLVARCHAR);
    
    mssql_bind($query, "@ClientDetailID", $client, SQLINT2);
    
    mssql_bind($query, "@ChildOrAdult", $data[$index][3], SQLBIT);
    
    mssql_bind($query, "@Notes", $data[$index][4], SQLVARCHAR);
    
    mssql_bind($query, "@Title", $data[$index][0], SQLVARCHAR);
    
    mssql_bind($query, "@FirstName", $data[$index][1], SQLVARCHAR);
    
    mssql_bind($query, "@Surname", $data[$index][2], SQLVARCHAR);
               
    if (($result = mssql_execute($query)) === false) 
    { 
        die('Could not execute the query query 2(Insert client)'); 
    } 
    
    ///--------------------------------------------
    
    
    	}
    //} 
    	
    //}						
    //mssql_bind($query, "@cost", $data[$index][4], SQLVARCHAR);	
    mssql_close()
    
    ?>
    <?PHP include 'footer.php'; ?>
    
    PHP:

     
    ghadacr, Aug 3, 2007 IP
  2. Doskono

    Doskono Peon

    Messages:
    153
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not quite sure why you are using a loop to input data into a database. I normally use mysql, so this might be why. but I don't think a loop or get statements is the best and most secure way of inputing data to a database
     
    Doskono, Aug 3, 2007 IP
  3. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Its becasue the form elements in the previous script are actually the same and i need to differentiate between them using an array....

    So when the data comes in it will be executed using a for each loop

    ., and i'm not using MYSQL, I'm using MSSQL and the code above is a Stored procedure which is used to store data into the code...
     
    ghadacr, Aug 3, 2007 IP