Page 1 of 1

FOR each help.....

Posted: Fri Aug 03, 2007 4:42 am
by ghadacr
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...

Code: Select all

<?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'; ?>

Posted: Fri Aug 03, 2007 6:29 am
by dream2rule

Code: Select all

$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)
{
Try using this code instead of the above code:

Code: Select all

$details = array($title, $firstname, $surname, $ChildAdult, $cost, $notes, $flight, $client);

foreach ($details as $index => $key)
{ 
          //your code here
}
Hope that helps.
:)

Posted: Fri Aug 03, 2007 6:59 am
by ghadacr
Thansk for the help dream2rule:

i have adapted the code as follows:

Code: Select all

$details = array($title, $firstname, $surname, $ChildAdult, $cost, $notes); 


foreach ($details as $index => $key) 
{

$query = mssql_init ("sp_insertFlightSpaces"); 

mssql_bind($query, "@FlightID", $flight, SQLVARCHAR);

mssql_bind($query, "@ClientDetailID", $client, SQLINT2);

mssql_bind($query, "@ChildOrAdult", $key[$ChildAdult], SQLBIT);

mssql_bind($query, "@Notes", $key[$notes], SQLVARCHAR);

mssql_bind($query, "@Title",$key[$title], SQLVARCHAR);

mssql_bind($query, "@FirstName", $key[$firstname], SQLVARCHAR);

mssql_bind($query, "@Surname", $key[$surname], SQLVARCHAR);

           
if (($result = mssql_execute($query)) === false) 
{ 
    die('Could not execute the query query 2(Insert client)'); 
} 

///--------------------------------------------

}
Something is happening on the database side, nut its inserting blanks.. I get the following errors:
Warning: Illegal offset type in

Fatal error: Only variables can be passed by reference

Posted: Fri Aug 03, 2007 8:35 am
by guitarlvr
Not positive but i think you have to change

Code: Select all

foreach ($details as $index => $key)
{

$query = mssql_init ("sp_insertFlightSpaces");

mssql_bind($query, "@FlightID", $flight, SQLVARCHAR);

mssql_bind($query, "@ClientDetailID", $client, SQLINT2);

mssql_bind($query, "@ChildOrAdult", $key[$ChildAdult], SQLBIT);

mssql_bind($query, "@Notes", $key[$notes], SQLVARCHAR);

mssql_bind($query, "@Title",$key[$title], SQLVARCHAR);

mssql_bind($query, "@FirstName", $key[$firstname], SQLVARCHAR);

mssql_bind($query, "@Surname", $key[$surname], SQLVARCHAR);
to:

Code: Select all

foreach ($details as $index => $key)
{

$query = mssql_init ("sp_insertFlightSpaces");

mssql_bind($query, "@FlightID", $flight, SQLVARCHAR);

mssql_bind($query, "@ClientDetailID", $client, SQLINT2);

mssql_bind($query, "@ChildOrAdult", $details['3'], SQLBIT);

mssql_bind($query, "@Notes", $details['5'], SQLVARCHAR);

mssql_bind($query, "@Title",$details['0'], SQLVARCHAR);

mssql_bind($query, "@FirstName", $details['1'], SQLVARCHAR);

mssql_bind($query, "@Surname", $details['2'], SQLVARCHAR);

Posted: Fri Aug 03, 2007 9:07 am
by ghadacr
thanks for the help guitarlvr, i did the changes. and i 'm just getting the following errors:
Notice: Array to string conversion in C:conflight.php on line 30

Notice: Array to string conversion in C:conflight.php on line 32

Notice: Array to string conversion in C:conflight.php on line 34

Notice: Array to string conversion in C:conflight.php on line 36
And within the database the columns say Array..... :?: :?:

Posted: Fri Aug 03, 2007 9:25 am
by iknownothing
change $details back to $key in your mssql_bind's and see what happens.

I think (Not 100%) $details is your Array, and $key are your array values...