FOR each help.....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

FOR each help.....

Post 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'; ?>
dream2rule
Forum Contributor
Posts: 109
Joined: Wed Jun 13, 2007 5:07 am

Post 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.
:)
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post 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
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post 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);
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post 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..... :?: :?:
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post 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...
Post Reply