Jump to content

I can't seem to entry my image file name into database!! Need Help!!


finaletech

Recommended Posts

Greetings Everyone!

 

I am working on a script to upload info for a project I am working on. This includes an image all works fine the image uploads onto the folder and all the rest info enters into database except for the image field it just enters value 1.  Can anyone assist me as to where the problem could be below is my script.

 

Regards

 

Finaletech

 

<?php 

if (isset($_POST['submitted'])) {

$target = "../../../uploads/"; 
     $target = $target . basename($_FILES['upload']['name']);	

require_once ('../../co-handles/mysqli_connect.php'); // Connect to the db.

$errors = array(); // Initialize an error array.
// Check for a pasha center:
	$ph = ($_FILES['upload']['name']); 

// Check for a pasha center:
if (empty($_POST['pcenter'])) {
	$errors[] = 'You forgot to enter your pasha center name.';
} else {
	$fn = mysqli_real_escape_string($dbc, trim($_POST['pcenter']));
}

// Check for a constituency:
if (empty($_POST['consti'])) {
	$errors[] = 'You forgot to enter your constituency.';
} else {
	$ln = mysqli_real_escape_string($dbc, trim($_POST['consti']));
}
// Check for a postal address:
if (empty($_POST['addpostal'])) {
	$errors[] = 'You forgot to enter your postal address.';
} else {
	$An = mysqli_real_escape_string($dbc, trim($_POST['addpostal']));
}
// Check for a physical address:
if (empty($_POST['addphy'])) {
	$errors[] = 'You forgot to enter your physical address.';
} else {
	$Ap = mysqli_real_escape_string($dbc, trim($_POST['addphy']));
}
// Check for a physical address:
if (empty($_POST['tel'])) {
	$errors[] = 'You forgot to enter your telephone number.';
} else {
	$Tn = mysqli_real_escape_string($dbc, trim($_POST['tel']));
}

// Check for an email address:
if (empty($_POST['email'])) {
	$errors[] = 'You forgot to enter your email address.';
} else {
	$e = mysqli_real_escape_string($dbc, trim($_POST['email']));
}
// Check for an email address:
if (empty($_POST['contact'])) {
	$errors[] = 'You forgot to enter your contact person.';
} else {
	$c = mysqli_real_escape_string($dbc, trim($_POST['contact']));
}
// Check for an email address:
if (isset($_POST['gcode']))  {

	$g = mysqli_real_escape_string($dbc, trim($_POST['gcode']));
}
// Check for an email address:
if (isset($_POST['status'])) {

	$s = mysqli_real_escape_string($dbc, trim($_POST['status']));
}
// Check for an email address:
if (isset($_POST['createdby'])) {

	$Cr = mysqli_real_escape_string($dbc, trim($_POST['createdby']));
}

// Check for a password and match against the confirmed password:
	if (empty($errors)) { // If everything's OK.

	// Register the user in the database...
//INSERT INTO `markets`(pcenter, consti, addpostal, addphy, tel, email, contact, g_code, status,  created_by, adddate) VALUES ('$pcenter', '$consti', '$addpostal', '$addphy', '$tel', '$email', '$contact', '$g_code', '$status', '$created_by', now())		
	// Make the query:
	$ph = (isset($_FILES['upload']));
			$q = "INSERT INTO markets (upload, pcenter, consti, addpostal, addphy, tel, email, contact, gcode, status, createdby, adddate) VALUES ('$ph', '$fn', '$ln', '$An', '$Ap', '$Tn', '$e', '$c', '$g', '$s', '$Cr', now())";		
	$r = mysqli_query ($dbc, $q); // Run the query.
	if ($r) { // If it ran OK.
	if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
echo "The file has been uploaded, and your information has been added to the directory"; 
} 
else { 

//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 
		// Print a message:
		echo '<h1>Thank you!</h1>
	<p>You have submitted a request to register. The Admin will email you!</p><p><br /></p>';	


	} else { // If it did not run OK.
echo "<table width=75% border=0 cellspacing=3 cellpadding=3 claass=boxborder align=center>";
echo "<h1>System Error</h1>";
  echo "<tr>";
echo "<td><p class=error>You could not be registered due to a system error. We apologize for any inconvenience.</p></td>";
  echo "</tr>";
    echo "<tr>";
echo "<td>'<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'</td>";
  echo "</tr>";

    echo "</table>";

		// Public message:


		// Debugging message:

	} // End of if ($r) IF.
//	if (file_exists ($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']) ) {
//	unlink ($_FILES['upload']['tmp_name']);
//	}



	mysqli_close($dbc); // Close the database connection.

	// Include the footer and quit the script:
	//include ('../../misc/phpmyql3_scripts/ch08/includes/footer.html'); 
	exit();

} else { // Report the errors.
echo "<table width=75% border=0 cellspacing=3 cellpadding=3 class=boxborder align=center>";
  echo "<tr>";
   echo "<td>";
   echo '<h1>Error!</h1>
	<p class="error">The following error(s) occurred:<br />';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p><p><br /></p>';
   echo "</td>";
echo "</tr>";
echo "</table>";





} // End of if (empty($errors)) IF.

mysqli_close($dbc); // Close the database connection.

} // End of the main Submit conditional.
?>

  • 2 weeks later...

Hello sir,

 

Check following statement in your code, You will get solution your self.

 

// Check for a pasha center:

$ph = ($_FILES['upload']['name']);

.

.

.

 

// Make the query:

$ph = (isset($_FILES['upload']));

 

Here you have overwrite $ph variable, So it will insert 0 or 1 to your database table.

 

Hope, You will understand what i mean

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.