What isthe matter

Please this is very urgent. I have a script that is ment to process a form and then store the result in my database but for some reason, I do not have it working… Here it is:

loggedin.php

<?php
		session_start(); // Start the session.

		// If no session value is present, redirect the user:
		ob_start();
		if (!isset($_SESSION['userID'])) {
			require_once ('loginFunction.inc.php');
			$url = absolute_url();
			header("Location: ".$url);
			exit();	
		}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Welcome to ADesigns: Home</title>
    <link href="css/main.css" rel="stylesheet" type="text/css" />
</head>

<body>

<table id="outerTable">
	<tr><td id="logo">
		<div>
			<img src="./images/logo.png" width="150"  height="55"  alt="company_logo" />
		</div>
	</td></tr>
	<tr><td id ="nav">
		<div>
			<a href="home.html">Home</a> |  
			<a href="participate.html">Participate</a> |
			<a href="aboutUs.html">About ADesigns</a> |
			<a href="contact.html">Contact Us</a>
		</div>
	</td></tr>
	<tr><td id="banner"> <! -- page banner image -->
		<img src="images/home.jpg" width="770" height="" alt="welcome to ADesigns">
	</td></tr>
	<tr><td>
		<table id="contentTable">
			<tr>
				<td id="topLeft">
					<br />
					<div id="welcomeBox">
						<h1>Advertisments</h1>
						<p>This section covers adverts from other companies</p>
					</div> <! -- mainContent -->
				</td>
				<td id="topRight">
					<br />
					<div id="loginRegBox">
					
					<?php	

						// Print a customized message:
						echo "<h1>Logged In!</h1> <p>You are now logged in, {$_SESSION['fname']}!</p>";
					?>
					<p><b>Congratualtion</b> on your successful login to our website. Now you can start the
					fun part and upload your designs. All you have to do is fill up the blanks appropriately.</p>
					
					<p><b>Note:</b> For each upload, you will need to specify that it is a 
					logo for your design, a picture of yourself or one of your designs.</p>
					<p>For ease of use you need to upload one file each for the following:</p>
						
					<p><b>Photograph:</b> a small picture of yourself for visitors to see. Only need once.</p>
					<p><b>Logo:</b> your company logo. Also only need one.</p>
						
					<form method="post" action="loggedin_v2.php" enctype="multipart/form-data" >
							<!--<div>
								<label for="uploadPhoto">Upload Photograph:</label>
								<input type="file" name="uploadPhoto"  id="upload"/>
							</div> -->
							<div>
								<label for="uploadLogo">Upload Logo:</label>
								<input type="file" name="uploadLogo"  id="upload"/>
							</div>
							
							<!--
								I do not need you at the moment:
								<div>
									<label for="imgType">Image Type:</label>
									<input type="radio" name="imageType" id="logo" value="logo" />Logo
									<input type="radio" name="imageType" id="photo" value="photo" />Photo
									<input type="radio" name="imageType" id="design" value="design" />Design
								</div>
							-->
							<div>
								<label for="brandID">Brand Identity:</label>
								<textarea name="brandID" rows="4" cols="40" id="brandID"></textarea>
							</div>
							<div>
								<label for="history">Please tell us about yourself:</label>
								<textarea name="history" rows="20" cols="40" id="history"></textarea>
							</div>
						
							<div>
								<input type="submit" name="btnSubmit" id="btnSubmit" value="Upload" />
							</div>
							
							
							
					</form>
					<p><a href="logout.php">Logout</a></p>
					</div> <! -- mainContentRight -->
			</tr>
			
		</table>
	</td></tr>
	<tr><td  id="footer"><div id="footerLastRow"><p>&copy; ADesigns  &nbsp;&nbsp; <a href="#">Privacy Policy</a> | <a href="#">Terms and Conditions</a></p></div></td></tr>
</table>



</body>
</html>


The processing is done here in loggedin_v2.php:

<?php
	
		/*Upon submission of scriipt from loggedin.html
		 *the form is sent here for process
		 */

		session_start(); //start session
		ob_start(); //prevent header errors
		
		if (!isset($_SESSION['userID']) )	{
			require_once ('loginFunction.inc.php');
			$url = absolute_url();
			header("loaction: " .$url);
			exit();
		}
		
		$page_title = 'Welcome to ADesigns: Logged In!';
		include ('includes/header.html');
		
	if(isset($_POST['btnSubmit']))	
	{	
		$error=array();
		
		//Check brand Identity 
			if (empty($_POST['brandID']))
			{
				$error[] ='You have no brand identity.';
			}
			else
			{
				$brandID =trim($_POST['brandID']);
			}
			
			//Check history
			if (empty($_POST['history']))
			{
				$error[] ='You have no history.';
			}
			else
			{
				$history =trim($_POST['history']);
			}
			
		
		
		if (isset($_FILES['upload']) )	
		{
	
			// 	Bail out if the file isn't really an upload.
		
			if (!is_uploaded_file($_FILES['upload']['tmp_name']))	
			{
				exit('There was no file uploaded!');
			}
		
			$uploadfile		=	$_FILES['upload']['tmp_name'];
			$uploadname		=	$_FILES['upload']['name'];
			$uploadtype		=	$_FILES['upload']['type'];
			$uploadBrandID	=	$_POST['brandID'];
			$uploadHistory	=   $_POST['history'];
			
			//	Open file or binary reading ('rb')
			$tempfile = fopen($uploadfile, 'rb');
		
		
			//	Read the entire file into memory using PHP's
			//	filesize fucntion to get the size.
			$filedata = fread($tempfile, filesize($uploadfile));
		
			//	Prepare for database insert by adding backslashes
			//	before special characters.
			$filedata = addslashes($filedata);
		
			
			if(!empty($error) )
			{
				//If all goes according to plan:
				
				require_once('mysql_connect.php');
			
				//	Create the SQL query.
				$sql = "INSERT INTO logo SET 
					filename = '$uploadname', 
					mimetype = '$uploadtype',
					description = '$uploaddesc',
					filedata = '$filedata',
					brandIdentity = '$uploadBrandID',
					history = '$uploadHistory'";
				
				//	Perform the insert.
				$ok = @mysql_query($sql);
		
				if(!$ok)	
				{
					exit('Database error storing file: ' . mysql_error());
				}
		
				header('location: ' . $_SERVER['PHP_SELF']);
				exit();
				
			
			} 
		
	     }
	    }

?>

Please I urgently need assistance with this.

Here is where I wan tthe result to be stored:

CREATE TABLE user (
    	userID MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
    	fname VARCHAR(20) NOT NULL,
	lname VARCHAR(20) NOT NULL,
	email VARCHAR(80) NOT NULL,
	category VARCHAR(40) NOT NULL,
	membership VARCHAR(20) NOT NULL,
	location VARCHAR(80) NOT NULL,
	username VARCHAR(30) NOT NULL,
    	password CHAR(40) NOT NULL,
	reg_date DATETIME NOT NULL,
	PRIMARY KEY (userID),
	UNIQUE(username),
	INDEX(password, username),
	UNIQUE(email)
) ENGINE=INNODB;

CREATE TABLE logo (
	userID MEDIUMINT UNSIGNED NOT NULL,
	logoID INT NOT NULL  AUTO_INCREMENT,
	filename VARCHAR(255) NOT NULL,
   	mimetype VARCHAR(50) NOT NULL,
         filedata MEDIUMBLOB,
	brandIdentity LONGTEXT NOT NULL,
	history LONGTEXT NOT NULL,
	PRIMARY KEY (logoID),
	FOREIGN KEY (userID) REFERENCES user(userID)
) ENGINE=INNODB;

CREATE TABLE design (
	userID MEDIUMINT UNSIGNED NOT NULL,
	dID INT NOT NULL  AUTO_INCREMENT,
	cat VARCHAR(40) NOT NULL,
	filename VARCHAR(255) NOT NULL,
   	mimetype VARCHAR(50) NOT NULL,
   	description VARCHAR(255) NOT NULL,
   	filedata MEDIUMBLOB,
	PRIMARY KEY (dID),
	FOREIGN KEY (userID) REFERENCES user(userID)
) ENGINE=INNODB;

The table of concern is the second one called logo

Please if ANYONE can help me, I would be very grateful.

What does ‘not working’ mean? Do you get errors? Or does it seem to work ok but it doesn’t store the data?

I do not get errors but the data is not being stored in my database. Am not certain that my validation works since it does not store the details in the database. Sorry for not making myself clear

Hey.

In your process page, at the bottom where you check if there were any errors, you do not have an else clause in there in case there was an error. So if there are errors, it just displays nothing.

You need to add an else clause that displays the error. Then you can actually fix the error.

I will get back shortly

at the very end of the script I added the following:

else{
				
					echo '<h1>System Error</h1>
					<p>You could upload due to a system error. We apologize for any inconvenience.</p>'; 
					
					 
					
					// Debugging message:
					echo '<p>' . mysql_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
				}

But It still does not work and It does not display the errors either.

You start ob_start at the start of your code but dont flush the buffer… so it wont put anything out!

It shouldn’t be at the very end. It should be at the closing bracket for the if statement that is checking the $error array.

Actually, all three of the last closing brackets in the file share this same problem. Each of them is missing a else clause that might result in you just seeing an empty page. You should add else clauses to all of them.

You should always make sure not to add conditional statements in such a way that it allows the code to just do… nothing. If you do, you end up creating very diagnostically annoying code; debugging it will be a major pain. (As you are discovering.)

The buffer is automatically flushed at the end of the script if you do not do it yourself.

On abnormal termination (fatal error) too?

Yep. The buffer is always flushed when the script ends, even if it ends early due to an error.

Ok so this is what I did. I belive I have taken care of the if statements :

<?php
	
		/*Upon submission of scriipt from loggedin.html
		 *the form is sent here for process
		 */

		session_start(); //start session
		ob_start(); //prevent header errors
		
		if (!isset($_SESSION['userID']) )	{
			require_once ('loginFunction.inc.php');
			$url = absolute_url();
			header("loaction: " .$url);
			exit();
		}
		
		$page_title = 'Welcome to ADesigns: Logged In!';
		include ('includes/header.html');
		
	if(isset($_POST['btnSubmit']))	
	{	
		$error=array();
		
		//Check brand Identity 
			if (empty($_POST['brandID']))
			{
				$error[] ='You have no brand identity.';
			}
			else
			{
				$brandID =trim($_POST['brandID']);
			}
			
			//Check history
			if (empty($_POST['history']))
			{
				$error[] ='You have no history.';
			}
			else
			{
				$history =trim($_POST['history']);
			}
			
		
		
		if (isset($_FILES['upload']) )	
		{
	
			// 	Bail out if the file isn't really an upload.
		
			if (!is_uploaded_file($_FILES['upload']['tmp_name']))	
			{
				exit('There was no file uploaded!');
			}
		
			$uploadfile		=	$_FILES['upload']['tmp_name'];
			$uploadname		=	$_FILES['upload']['name'];
			$uploadtype		=	$_FILES['upload']['type'];
			$uploadBrandID	=	$_POST['brandID'];
			$uploadHistory	=   $_POST['history'];
			
			//	Open file or binary reading ('rb')
			$tempfile = fopen($uploadfile, 'rb');
		
		
			//	Read the entire file into memory using PHP's
			//	filesize fucntion to get the size.
			$filedata = fread($tempfile, filesize($uploadfile));
		
			//	Prepare for database insert by adding backslashes
			//	before special characters.
			$filedata = addslashes($filedata);
		
			
			if(!empty($error) )
			{
				//If all goes according to plan:
				
				require_once('mysql_connect.php');
			
				//	Create the SQL query.
				$sql = "INSERT INTO logo SET 
					filename = '$uploadname', 
					mimetype = '$uploadtype',
					description = '$uploaddesc',
					filedata = '$filedata',
					brandIdentity = '$uploadBrandID',
					history = '$uploadHistory'";
				
				//	Perform the insert.
				$ok = @mysql_query($sql);
		
				if(!$ok)	
				{
					exit('Database error storing file: ' . mysql_error());
				}
				
				else
				{
					echo '<h1>System Error</h1>
					<p>Looks like we have a problem due to a system error. We apologize for any inconvenience.</p>'; 
					
					// Debugging message:
					echo '<p>' . mysql_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
				}
		
				header('location: ' . $_SERVER['PHP_SELF']);
				exit();
				
			
			} 
			
			else
			{
				
				echo '<h1>System Error</h1>
				<p>You could upload due to a system error. We apologize for any inconvenience.</p>'; 
					
				// Debugging message:
				echo '<p>' . mysql_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
			}
				
		
	     }
	    }

?>

And the result is?

Nope, the code you posted still has the two outer most if statements without an else cause, so that if the submit button or the file isn’t sent, you only get a blank page.

See the two last } chars in the code. They are the closing brackets for those two if statements.

And, like guido2004 pointed out, you didn’t actually say what the result of that code was. (That’s kind of an important piece of info when debugging a piece of code :D)