Hello to all,
Well my program is coming along fine. Thanks to devdiva, rachel, and The Defender for feedback and support. I have a small problem with my data collection. I can collect all the data except for uploading of the image for lets say a student or in my case an offender. I have a script I named insert.php, which is called upon when the user submits the offense info. However, I had problems when it came to uploading the pic. I was generating fread and fopen errors. The script is as follows and please bear with me as I am new to PHP. Prior to me adding the new lines everything worked fine with the exception of the photo. The script will not upload no data now with the new lines, however;my fread and fopen errors disappeared.
<?PHP
if ($submit) { //ADDED THIS LINE!
//Connect to database
include "open_db.inc";
// Inserting the data into users table
// -----------------------------
// Convert time to Mysql Format
$datesplit = explode("/", $dob);
$dobdate = $datesplit[2]."-".$datesplit[0]."-".$datesplit[1];
#Insert Values into Persons Table
$sql = "INSERT INTO persons VALUES ('','$name','$dobdate','$RaceDrop')";
$result = mysql_query($sql,$db) or die("Select DB Error: ".mysql_error());
// Check to see if offense data field contains data
if( isset($offense) ) {
// get the user id
$userid = mysql_insert_id();
// Convert date and time formats to Mysql format
$datesplit = explode("/", $dateDet);
$detdate = $datesplit[2]."-".$datesplit[0]."-".$datesplit[1];
$datesplit = explode("/", $dateRel);
$Reldate = $datesplit[2]."-".$datesplit[0]."-".$datesplit[1];
$datesplit = explode("/", $dateOfOff);
$Offdate = $datesplit[2]."-".$datesplit[0]."-".$datesplit[1];
//Upload image of offender
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
// Insert data into offense table
$sql = "INSERT INTO offense VALUES ('','$userid','$detdate','$timeDet','$Reldate','$timeRel','$lockedDrop',";
$sql .="'$sightDrop','$officerCode','$officerName','$caseNo','$Offdate','$comment','$data','$offense','filename','filesize','filetype')";
$result = mysql_query( $sql,$db ) or die("Select DB Error: ".mysql_error());
//ADDED THIS LINE
} //ADDED THIS LINE
mysql_free_result($result);
mysql_close($db);
} //ADDED THIS LINE
?>
Generated errors:
Warning: fopen(C:\Documents and Settings\Administrator\My Documents\My Pictures\xSuperchief0101.jpg): failed to open stream: Permission denied in c:\apache\htdocs\login\insert.php on line 45
Warning: filesize(): Stat failed for C:\Documents and Settings\Administrator\My Documents\My Pictures\xSuperchief0101.jpg (errno=2 - No such file or directory) in c:\apache\htdocs\login\insert.php on line 45
Warning: fread(): supplied argument is not a valid stream resource in c:\apache\htdocs\login\insert.php on line 45
Select DB Error: Duplicate entry '0' for key 1
As usual, any feedback is appreciated.
jchapa