.
Antnee;
Thanks for helping out with my problem.
Yes.
I’m using the phpMyAdmin. I can insert a new row with the phpMyAdmin “Insert” button and it creates a NULL record in the Opponent row.
It’s just with the PHP script that inserting a row with the $team_id_opp set to NULL that the Opponent row sets to 0 (this might be a question for the PHP forum).
I was thinking yesterday that I might ought to post the PHP script. I just didn’t want to put too much information in one post.
If you scroll about 3/5’s of the way down the page you will see the snippet:
// --------------------------------------------------
// ### For non d1 opponent empty team id. ###
// --------------------------------------------------
$team_id_opp = NULL;
Then if you look down at the first query you will see the following:
(The query is not yet complete. I am still working on it.)
[COLOR=“#FF0000”]
team_id,
Year,
game_id,
GameDate,
GameOrder,
Stadium,
Opponent,
NonD1 )
VALUES[/COLOR]
(‘$team_id’,
‘$Year’,
‘$game_id_this_team’,
‘$GameDateTS’,
‘$Sec’,
‘$StadiumThisTeam’,
‘$team_id_opp’, // This value should be NULL when the $team_id_opp var above is set to NULL but it sets to 0 instead.
‘$ShiftedOffNonD1’)"
<?php
// ############################################################
// ### ###
// ### ###
// ### ###
// ### ###
// ############################################################
// --------------------------------------------------
// ### Assign post values to vars. ###
// --------------------------------------------------
$Month = $_POST["Month"];
$Day = $_POST["Day"];
$GameOrder = $_POST["GameOrder"];
$Stadium = $_POST["Stadium"];
$Opponent = $_POST["Opponent"];
$NonD1 = $_POST["NonD1"];
//$Comment = $_POST["Comment"];
//$Status = $_POST["Status"];
//$Innings = $_POST["Innings"];
//$Outcome = $_POST["Outcome"];
//$RunsScored = $_POST["RunsScored"];
//$OpponentScore = $_POST["OpponentScore"];
//$tourn_id = $_POST["tourn_id"];
//$TournHomeTeam = $_POST["TournHomeTeam"];
//$Bracket = $_POST["Bracket"];
//$Finals = $_POST["Finals"];
//$TournGameNum = $_POST["TournGameNum"];
//$ = $_POST[""];
//$ = $_POST[""];
// --------------------------------------------------
// ### Call the configuration file for the MySQL database. ###
// --------------------------------------------------
require('/home/content/59/4519259/html/baseball/conf/config.inc.php');
// --------------------------------------------------
// ### Set the default time zone. ###
// --------------------------------------------------
date_default_timezone_set('America/New_York');
// --------------------------------------------------
// ### Tells session start the name of the session cookie. ###
// --------------------------------------------------
session_name("AdminSession");
// --------------------------------------------------
// ### Start the session. ###
// --------------------------------------------------
session_start();
// --------------------------------------------------
// ### Assign session vars num add, year, and team id to vars. ###
// --------------------------------------------------
$NumAdd = $_SESSION["NumAdd"];
$Year = $_SESSION["Year"];
// --------------------------------------------------
// ### Set both vars to type integer. ###
// --------------------------------------------------
settype($NumAdd,"integer");
settype($Year,"integer");
// --------------------------------------------------
// ### Set both vars to type integer. ###
// --------------------------------------------------
$ValidRecord = FALSE;
// --------------------------------------------------
// ### Require the function to find the game ids for this team and the opponent. ###
// --------------------------------------------------
require('./functions/GameRef.inc.php');
// --------------------------------------------------
// ### Remove empty values from non d1 array. ###
// --------------------------------------------------
$NonD1 = array_filter($NonD1);
// --------------------------------------------------
// ### Loop through each of the games to be added. ###
// --------------------------------------------------
for ($n = 0; $n < $NumAdd; $n++){
// --------------------------------------------------
// ### Assign session var to team id var. ###
// --------------------------------------------------
$team_id = $_SESSION["team_id"];
// --------------------------------------------------
// ### Assign game order, month, day array values to vars. ###
// --------------------------------------------------
$Sec = $GameOrder[$n];
$M = $Month[$n];
$D = $Day[$n];
// --------------------------------------------------
// ### Set type to integer. ###
// --------------------------------------------------
settype($Sec, "integer");
settype($M, "integer");
settype($D, "integer");
// --------------------------------------------------
// ### mktime (hour, minute, second, month, day, year) Make time stamp. Game order is seconds past midnight Eastern Time. ###
// --------------------------------------------------
$GameDateTS = mktime(0,0,$Sec,$M,$D,$Year);
// --------------------------------------------------
// ### If conditionals for stadium. ###
// --------------------------------------------------
if ($Stadium[$n] == 'vs'){
$StadiumThisTeam = 'vs';
$StadiumOpponent = 'at';
}
if ($Stadium[$n] == 'at'){
$StadiumThisTeam = 'at';
$StadiumOpponent = 'vs';
}
if ($Stadium[$n] == 'neu'){
$StadiumThisTeam = 'neu';
$StadiumOpponent = 'neu';
}
if ($Stadium[$n] == 't'){
$StadiumThisTeam = 't';
$StadiumOpponent = 't';
}
if ($Stadium[$n] == 'c'){
$StadiumThisTeam = 'c';
$StadiumOpponent = 'c';
}
if ($Stadium[$n] == 'r'){
$StadiumThisTeam = 'r';
$StadiumOpponent = 'r';
}
if ($Stadium[$n] == 'sr'){
$StadiumThisTeam = 'sr';
$StadiumOpponent = 'sr';
}
if ($Stadium[$n] == 'cws'){
$StadiumThisTeam = 'cws';
$StadiumOpponent = 'cws';
}
// --------------------------------------------------
// ### Team id for the opponent. ###
// --------------------------------------------------
$team_id_opp = $Opponent[$n];
// --------------------------------------------------
// ### Call the game id reference function. Calculates the game ids for this team and for the opponent. ###
// --------------------------------------------------
GameRef($MySQLi,$team_id_opp);
// --------------------------------------------------
// ### If month, day, and D1 opponent has been selected. ###
// --------------------------------------------------
if ( (!empty($Opponent[$n])) AND
(!empty($Month[$n])) AND
(!empty($Day[$n])) AND
(empty($NonD1[$n])) ){
// --------------------------------------------------
// ### Since this opponent is a d1 school set non d1 to empty. ###
// --------------------------------------------------
$ShiftedOffNonD1 = '';
// --------------------------------------------------
// ### Set valid record to true. ###
// --------------------------------------------------
$ValidRecord = TRUE;
}
// --------------------------------------------------
// ### If month, day, and non D1 opponent has been input. ###
// --------------------------------------------------
if ( (count($NonD1) > 0) AND
(!empty($Month[$n])) AND
(!empty($Day[$n])) AND
(empty($Opponent[$n])) ) {
// --------------------------------------------------
// ### For non d1 opponent empty team id. ###
// --------------------------------------------------
$team_id_opp = NULL;
// --------------------------------------------------
// ### Shift off and assign the first value off the non d1 opponent array to non d1 var. ###
// --------------------------------------------------
$ShiftedOffNonD1 = array_shift($NonD1);
// --------------------------------------------------
// ### Set valid record to true. ###
// --------------------------------------------------
$ValidRecord = TRUE;
}
// --------------------------------------------------
// ### If user has input enough this loop to make this a valid record. ###
// --------------------------------------------------
if ($ValidRecord == TRUE){
//$team_id = $MySQLi -> real_escape_string($team_id);
//$Year = $MySQLi -> real_escape_string($Year);
//$game_id_this_team = $MySQLi -> real_escape_string($game_id_this_team);
// --------------------------------------------------
// ### Insert game record into database for this team. ###
// --------------------------------------------------
$MySQLi -> query("INSERT INTO Games
( team_id,
Year,
game_id,
GameDate,
GameOrder,
Stadium,
Opponent,
NonD1 )
VALUES
('$team_id',
'$Year',
'$game_id_this_team',
'$GameDateTS',
'$Sec',
'$StadiumThisTeam',
'$team_id_opp',
'$ShiftedOffNonD1')");
}
// --------------------------------------------------
// ### If input is valid and opposing team is a d1 opponent. ###
// --------------------------------------------------
if ( ($ValidRecord == TRUE) AND (!empty($team_id_opp)) ){
// --------------------------------------------------
// ### Insert game record into database for opposing team. ###
// --------------------------------------------------
$MySQLi -> query("INSERT INTO Games
( team_id,
Year,
game_id,
GameDate,
GameOrder,
Stadium,
Opponent,
NonD1 )
VALUES
('$team_id_opp',
'$Year',
'$game_id_opponent',
'$GameDateTS',
'$Sec',
'$StadiumOpponent',
'$team_id',
'$ShiftedOffNonD1')");
}
// --------------------------------------------------
// ### Set valid record back to false for next loop. ###
// --------------------------------------------------
$ValidRecord = FALSE;
// --------------------------------------------------
// ### Set this var to empty in case next opponent is non d1 team. ###
// --------------------------------------------------
$team_id_opp = '';
// --------------------------------------------------
// ### Close for loop. ###
// --------------------------------------------------
}
/*
// --------------------------------------------------
// ### Run the mysql query insert into db. ###
// --------------------------------------------------
@ mysql_query("INSERT INTO Members
( remote_address,
web_ring,
email,
username,
password,
join_date,
domain_name,
your_name,
mailing_address,
business_name,
address_locale,
state_business )
VALUES
('$InternetProtocol',
'$WebRing',
'$Email',
'$UserName',
'$PassWord1',
'$CurrTS',
'$DomainName',
'$YourName',
'$StreetAddress',
'$BusinessName',
'$Locale',
'$DescribeBusiness')");
*/
// --------------------------------------------------
// ### Free the result. ###
// --------------------------------------------------
//$Result->free();
?>