Jump to content
Larry Ullman's Book Forums

I Cannot Seem To Enter Image File Name Into Database Need Help!


Recommended Posts

20.01.12

 

Greetings,

 

I am working on an application to map a community and I need to upload an image together with relevent info. So I used the script registration and slightly cannibalised it to meet my needs. Well all works fine the image uploads to the folder and info inserts into the database except for the image field instead of the file name it inserts the value of 1. I have the field value as varchar what could be the problem here need help.Below is my script

 

regards

 

finaletech

 

<html>

<head>

<title>Finaletouch User Management</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link rel="stylesheet" type="text/css" href="../../style.css" />

</head>

<body bgcolor="#FFFFFF" text="#000000">

 

<?php

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

 

$target = "../../../uploads/";

$target = $target . basename($_FILES['photo']['name']);

 

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

 

$errors = array(); // Initialize an error array.

// Check for a pasha center:

if (!isset($_FILES['photo'])) {

$error[] = 'You forgot to select an image.';

} else {

$ph = (isset($_FILES['photo']['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['photo']));

$q = "INSERT INTO markets (photo, 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['photo']['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 ('file:///C|/Users/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>";

Link to comment
Share on other sites

 Share

×
×
  • Create New...