/    Sign up×
Community /Pin to ProfileBookmark

Store path to the DB

I could find a code here like bellow

[CODE]
<?php

// filename: upload.processor.php

// first let’s set some variables

include(“conf.php”);

// News has been entered
// using the form below.

// open database connection
$connection = mysql_connect($host, $user, $pass) or die (“Unable to connect!”);
// select database
mysql_select_db($db) or die (“Unable to select database!”);

// make a note of the current working directory, relative to root.
$directory_self = str_replace(basename($_SERVER[‘PHP_SELF’]), ”, $_SERVER[‘PHP_SELF’]);

// make a note of the directory that will recieve the uploaded files
$uploadsDirectory = $_SERVER[‘DOCUMENT_ROOT’] . $directory_self . ‘uploaded_files/’;

// make a note of the location of the upload form in case we need it
$uploadForm = ‘http://’ . $_SERVER[‘HTTP_HOST’] . $directory_self . ‘multiple.upload.form.php’;

// make a note of the location of the success page
$uploadSuccess = ‘http://’ . $_SERVER[‘HTTP_HOST’] . $directory_self . ‘multiple.upload.success.php’;

// name of the fieldname used for the file in the HTML form
$fieldname = ‘file’;

//echo'<pre>’;print_r($_FILES);exit;

// Now let’s deal with the uploaded files

// possible PHP upload errors
$errors = array(1 => ‘php.ini max file size exceeded’,
2 => ‘html form max file size exceeded’,
3 => ‘file upload was only partial’,
4 => ‘no file was attached’);

// check the upload form was actually submitted else print form
isset($_POST[‘submit’])
or error(‘the upload form is neaded’, $uploadForm);

// check if any files were uploaded and if
// so store the active $_FILES array keys
$active_keys = array();
foreach($_FILES[$fieldname][‘name’] as $key => $filename)
{
if(!empty($filename))
{
$active_keys[] = $key;
}
}

// check at least one file was uploaded
count($active_keys)
or error(‘No files were uploaded’, $uploadForm);

// check for standard uploading errors
foreach($active_keys as $key)
{
($_FILES[$fieldname][‘error’][$key] == 0)
or error($_FILES[$fieldname][‘tmp_name’][$key].’: ‘.$errors[$_FILES[$fieldname][‘error’][$key]], $uploadForm);
}

// check that the file we are working on really was an HTTP upload
foreach($active_keys as $key)
{
@is_uploaded_file($_FILES[$fieldname][‘tmp_name’][$key])
or error($_FILES[$fieldname][‘tmp_name’][$key].’ not an HTTP upload’, $uploadForm);
}

// validation… since this is an image upload script we
// should run a check to make sure the upload is an image
foreach($active_keys as $key)
{
@getimagesize($_FILES[$fieldname][‘tmp_name’][$key])
or error($_FILES[$fieldname][‘tmp_name’][$key].’ not an image’, $uploadForm);
}

// make a unique filename for the uploaded file and check it is
// not taken… if it is keep trying until we find a vacant one
foreach($active_keys as $key)
{
$now = time();
while(file_exists($uploadFilename[$key] = $uploadsDirectory.$now.’-‘.$_FILES[$fieldname][‘name’][$key]))
{
$now++;

}
}

// now let’s move the file to its final and allocate it with the new filename

foreach($active_keys as $key)
{
@move_uploaded_file($_FILES[$fieldname][‘tmp_name’][$key], $uploadFilename[$key])
or error(‘receiving directory insuffiecient permission’, $uploadForm);

}
?>
[/CODE]

[CODE]
<?php

# Assuming image1

#set some variables
$query_part_1 = ”;
$query_part_2 = ”;
$i = 1;

foreach($active_keys as $key)
{
$query_part_1 .= “,’image” . $i++ . “‘”;
$query_part_2 .= “,'” . $_FILES[$fieldname][‘name’][$key] . “‘”;
}

$query = “INSERT INTO properties (‘location’,’description'” . $query_part_1 . “) VALUES (‘” . $location . “‘,'” . $description . “‘” . $query_part_2 . “)”;

?>
[/CODE]

But when I try to store image to the DB it gives sintax error…

[QUOTE]

INSERT INTO properties (‘location’,’description’,’image1′) VALUES (”,”,’1299111288_1195156829_1.jpg’)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”location’,’description’,’image1′) VALUES (”,”,’1299111288_1195156829_1.jpg’)’ at line 1

[/QUOTE]

Could you please help me to build the correct query ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@dmaarc123May 31.2012 — I try my best not find any solution for this, may be problem with your value.

Sorry I'm not able to help you.

?
Copy linkTweet thisAlerts:
@NogDogMay 31.2012 — Do not use normal quotes around table or column names. If you need/want to quote them, use the back-tick quote. 'Straight quotes' are only for string literals.
×

Success!

Help @streamland spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...