Well I tried using mysql_error and still get nothing (I echo it to the screen and it prints a blank) and I also tried chaning ID to not null auto increment in the database but it still kept it as null auto_increment even after I changed it to not null auto_increment. I do have an '@' in my code but way before that in not in a query but in a split function call. I will post the whole code then:
<?php
$dbname="mydb";
$dbhost="Schemp";
$NewUserType="Student"; //Assumed to all be students in the roster
if (!($db = mysql_connect("localhost", "root")))
echo "error connecting to ". $dbname ."on ". $dbhost;
mysql_select_db($dbname,$db);
$content = file("/usr/local/mysql/bin/datafiles/test.txt");
while (list($key, $val) = each ($content))
{
$data = explode("\t", $val);
$NewUserSSN = $data[2];
$NewUserBearIDArray = split('[@]', $data[3]);
$NewUserBearID = $NewUserBearIDArray[0];
$bearid_result = mysql_query("select BearID from User where
BearID='$NewUserBearID' ");
$num_bearid_records = mysql_num_rows($bearid_result);
if($num_bearid_records <1)
{
$BearIDFlag=FALSE;
} else
{
$BearIDFlag=TRUE;
}
$ssn_result = mysql_query("select SSN from User where SSN='$NewUserSSN' ");
$num_ssn_records = mysql_num_rows($ssn_result);
if ($num_ssn_records < 1)
{
$SSNFlag=FALSE;
} else
{
{
$SSNFlag=TRUE;
}
if (($BearIDFlag==TRUE)||($SSNFlag==TRUE))
{
echo "BearID flag or SSNFlag is true!";
$ssn_roster_result=mysql_query("select from Roster where SSN = '$NewUserSSN' ");
$num_ssn_roster_records=mysql_num_rows($ssn_roster_result);
if ($num_ssn_roster_records < 1)
{
$SSNRosterFlag=FALSE;
} else
{
$SSNRosterFlag=TRUE;
}
$bearid_roster_result=mysql_query(" select from Roster where Email='$data[3]' ");
$num_bearid_roster_records=mysql_num_rows($bearid_roster_result);
if ($num_bearid_roster_records < 1)
{
$BearIDRosterFlag=FALSE;
} else
{
$BearIDRosterFlag=TRUE;
}
if (($BearIDRosterFlag==TRUE)||($SSNRosterFlag==TRUE))
{
die("User already is in the Roster and User table!");
} else
{
$sql=sprintf("INSERT into Roster VALUES (NULL, '%s', '%s', '%s', '%s', '%s')",
$data[0], $data[1], $data[2], $data[3], $data[4], $data[5]);
}
}
if (($BearIDFlag==FALSE)&&($SSNFlag==FALSE))
{
echo "BearIDFlag and SSNFlag is false! <br>";
echo $NewUserBearID;
echo "<br>";
echo $NewUserSSN;
echo "<br>";
echo $NewUserType;
echo "<br>";
//Add user to the user table, assumed to all be students
$AddUser="INSERT into User (ID, BearID, SSN, UserType) VALUES
(NULL, '$NewUserBearID', '$NewUserSSN', '$NewUserType')";
$error= mysql_error();
echo $error;
echo "<br>";
$ssn_roster_result=mysql_query("select from Roster where SSN='$NewUserSSN' ");
$num_ssn_roster_records=mysql_num_rows($ssn_roster_result);
if ($num_ssn_roster_records < 1)
{
$SSNRosterFlag=FALSE;
} else {
$SSNRosterFlag=TRUE; }
$bearid_roster_result=mysql_query(" select from Roster where Email = '$data[3]'");
$num_bearid_roster_records=mysql_num_rows($bearid_roster_result);
if ($num_bearid_roster_records <1)
{
$BearIDRosterFlag=FALSE;
} else {
$BearIDRoster=TRUE; }
if (($BearIDRosterFlag==TRUE)||($SSNRosterFlag==TRUE))
{
die ("User already is in Roster table!");
} else {
$sql= sprintf("INSERT into Roster VALUES (NULL, '%s', '%s', '%s', '%s')",
$data[0], $data[1], $data[2], $data[3], $data[4]);
}
$result = mysql_query($sql, $db);
}
}
?>
basically this code is to parse through a text file, see if they exist in thte user table and if they do not create them, if they do exist check to see if they are in the roster table and if they are not add them else the program prints an error message. Anyway, any ideas anyone?
Laura Young