learning_brain
New Member
- Messages
- 206
- Reaction score
- 1
- Points
- 0
Haven't been on for a while but I'm stuck!!!!!
I have a table with 3 image links in MySQL
In the add record page, I want to 1) upload the images to the server and 2) insert the paths to the database.
I'm referencing a tut at http://php.about.com/od/phpwithmysql/ss/Upload_file_sql_3.htm
The form (or the main bits of it)
The insert
The upload..
But I'm getting this error...
So I tried with the sanitising function in the MySQL insert statement...
GetSQLValueString($_FILES['image_1']['title']),
GetSQLValueString($_FILES['image_2']['title']),
GetSQLValueString($_FILES['image_3']['title']),
and got this..
Could someone help to let me know where I'm going wrong?
Many thanks
Rich
I have a table with 3 image links in MySQL
In the add record page, I want to 1) upload the images to the server and 2) insert the paths to the database.
I'm referencing a tut at http://php.about.com/od/phpwithmysql/ss/Upload_file_sql_3.htm
The form (or the main bits of it)
HTML:
<input name="title" type="text" id="title" size="50" />
<label>Upload Image 1
<input type="file" name="image_1" id="image_1" />
</label>
<label>Upload Image 2
<input type="file" name="image_2" id="image_2" />
</label>
<label>Upload Image 3
<input type="file" name="image_3" id="image_3" />
</label>
The insert
PHP:
//specify targets
$target = "itemimages/";
$target1 = $target . basename( $_FILES['image_1']['title']);
$target2 = $target . basename( $_FILES['image_2']['title']);
$target3 = $target . basename( $_FILES['image_3']['title']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO items (image_1, image_2, image_3, time_added, title, `description`, category, price) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
$_FILES['image_1']['title'],
$_FILES['image_2']['title'],
$_FILES['image_3']['title'],
GetSQLValueString($_POST['time_added'], "int"),
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['category'], "text"),
GetSQLValueString($_POST['price'], "double"));
mysql_select_db($database_skinnerandhyde, $skinnerandhyde);
$Result1 = mysql_query($insertSQL, $skinnerandhyde) or die(mysql_error());
The upload..
PHP:
//Write image to server
if(move_uploaded_file($_FILES['image_1']['tmp_name'], $target1))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if(move_uploaded_file($_FILES['image_2']['tmp_name'], $target2))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if(move_uploaded_file($_FILES['image_3']['tmp_name'], $target3))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
But I'm getting this error...
Code:
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 ' , , 1307183343, 'test', 'sfgdfgdfhdghd', 'test', '9.99')' at line 1
So I tried with the sanitising function in the MySQL insert statement...
GetSQLValueString($_FILES['image_1']['title']),
GetSQLValueString($_FILES['image_2']['title']),
GetSQLValueString($_FILES['image_3']['title']),
and got this..
Code:
[B]Warning[/B]: Missing argument 2 for GetSQLValueString(), called in /home/skinne29/public_html/admin/add.php on line 89 and defined in [B]/home/skinne29/public_html/admin/add.php[/B] on line [B]48[/B]
[B]Warning[/B]: Missing argument 2 for GetSQLValueString(), called in /home/skinne29/public_html/admin/add.php on line 90 and defined in [B]/home/skinne29/public_html/admin/add.php[/B] on line [B]48[/B]
[B]Warning[/B]: Missing argument 2 for GetSQLValueString(), called in /home/skinne29/public_html/admin/add.php on line 91 and defined in [B]/home/skinne29/public_html/admin/add.php[/B] on line [B]48[/B]
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 ' , , 1307183690, 'gdfgdfg', 'dfgdgh', 'dfdhgdfh', '9.99')' at line 1
Could someone help to let me know where I'm going wrong?
Many thanks
Rich
Last edited: