Ok... I have a noobie issue.
I am trying to upload a photo to specific directory on my server. (this is working correctly with the code below). However, I am also trying to rename the file and upload that filename to a mysql database (users.photo).
This is my code.. it shows no errors but it does not add it to my server.
HELP WOULD BE SO APPRECIATED!!\ -
-
<?php require_once('../Connections/JMI10.php');
-
-
if (!function_exists("GetSQLValueString")) {
-
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
-
{
-
if (PHP_VERSION < 6) {
-
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
-
}
-
-
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
-
-
switch ($theType) {
-
case "text":
-
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
-
break;
-
case "long":
-
case "int":
-
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
-
break;
-
case "double":
-
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
-
break;
-
case "date":
-
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
-
break;
-
case "defined":
-
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
-
break;
-
}
-
return $theValue;
-
}
-
}
-
?>
-
<?php
-
$colname_Recordset1 = "-1";
-
if (isset($_SESSION['MM_Username'])) {
-
$colname_Recordset1 = $_SESSION['MM_Username'];
-
}
-
mysql_select_db($database_JMI10, $JMI10);
-
$query_Recordset1 = sprintf("SELECT * FROM `user` WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
-
$Recordset1 = mysql_query($query_Recordset1, $JMI10) or die(mysql_error());
-
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
-
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
-
?>
-
<?
-
//This is the directory where images will be saved
-
$target = "/home/content/n/w/c/nwclark/html/jmi2/secure/idphotos/";
-
$target = $target . basename( $_FILES['photo']['name']);
-
-
//This gets all the other information from the form
-
$name=$_POST['username'];
-
$pic=($_FILES['photo']);
-
$width = 640;
-
$height = 480;
-
//Writes the information to the database
-
mysql_query("INSERT INTO `user` VALUES ('$name', '$pic')") ;
-
-
//Writes the photo to the server
-
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
-
{
-
-
//Tells you if its all ok
-
echo "The file ". basename( $_FILES['uploadedfile']['name']). " 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.";
-
}
-
-
mysql_free_result($Recordset1);
-
?>
-
-
-
7 2470
You can use mysql_error() to retrieve the latest error, otherwise, mysql will not tell you any errors. Add or die(mysql_error()) to your mysql function calls. -
mysql_query("INSERT INTO `user` VALUES ('$name', '$pic')") or die("Error: " . mysql_error());
-
Oh.. ok.. cool .. i should've known that.
i get this error..
Error: Column count doesn't match value count at row 1
If you omit the column names from the INSERT statement, MySQL assumes you're going to supply data for every column. After all, how would it know which columns to put data in?
You can either add the column names to your query, or provide values for every column in the VALUES section.
ok.. sorry to sound so ignorant.. (which i am) .. how would you do that?
BTW: I owe you big time.. working hard to learn PHP/MYSQL
Not being sure how your table is set up, I'll use an example.
Table set up: -
Database: User
-
Table: Photos
-
Columsn: id | photo_name | photo_upload_time | photo_tags
-
Inserting only 2 fields (no fields defined in Insert) -
INSERT INTO
-
`User.Photos`
-
/** No fields defined here **/
-
VALUES
-
(
-
'photo.jpg',
-
'00:00:00'
-
);
-
That would cause the same error you received, for the previously mentioned reason.
The code revised: -
INSERT INTO
-
`User.Photos`
-
(
-
'photo_name',
-
'photo_upload_time'
-
)
-
VALUES
-
(
-
'photo.jpg',
-
'00:00:00'
-
);
-
See that we have now specified which fields should have the data inserted?
If you do want to omit giving the fields, you will have to provide all fields in the VALUES. -
INSERT INTO
-
`User.Photos`
-
/** No fields defined here **/
-
VALUES
-
(
-
'id',
-
'photo.jpg',
-
'my photo'
-
'a, cool, photo'
-
);
-
Understand?
Mark.
Starting to i think .. but none of these option work.. I guess the issue is that i am trying to update a single column on the user table. I did that rather than creating a whole new table for the photo name.
so the basic db design is:
table=user
column=photo
I want to place the photo name there and nothing else.
Atli 5,058
Expert 4TB
Hi.
Line #53 of your code:
And then you go on to use $pic as a string in your INSERT query on line #57.
This would put "Array" into the query, which I assume you don't want.
You probably mean to do this: - $pic = $_FILES['photo']['name'];
As to the other thing...
Like Markus says, your INSERT statements needs to provide values for EVERY column in the table that needs one. But you can leave out columns that have default values.
You just need to specify which columns you want to provide values for. (Not specifying the columns, like you do in your INSERT query, is never good. You should always specify the columns you plan to use, even if you are going to use all of them. Allows you to add to the table later on without messing up your old queries.)
For example: -
INSERT INTO `user`(`name`, `pic`)
-
VALUES ('$name', '$pic')
-
Assuming the names of the columns are `name` and `pic`, and that there are no other columns in the table that do not have a default value.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Terry A. Haimann |
last post by:
I have an application, DipperBase, that keeps astronomical images in a
mysql database. The actual images are stored in a blob field. To get
some test data, I downloaded some SEDS images of...
|
by: Ian Davies |
last post by:
Hello all
The following code allows me to connect to a local MySQL database on my pc
from a VB6 project.
****************************************************************************
**
Dim...
|
by: Pitcairnia |
last post by:
The basic purpose of the site is for authenticated users to post event
listings, which often include photographs. The user is faced with a page
where they can insert all of the information about...
|
by: Ramakrishnan Nagarajan |
last post by:
Hi,
I am facing a different problem in my application. In that I am uploading a
folder that contain only images. Everything was done and was working fine
too. When I executed the application using...
|
by: C.Joseph Drayton |
last post by:
Hi All,
I have a web site I am developing, and have a question. I would like
members to be able to upload pictures.
Do you think they should be saved as individual files or should they be
put...
|
by: joe |
last post by:
Any articles relating with
Uploading images files to server and resize the image by asp.net 2.0
|
by: w33nie |
last post by:
What I'm trying to do here, is upload a video to the ../video/ folder, and up to 5 images to the ../images/ folder. As well as the database information like title, content and each file's file...
|
by: geert |
last post by:
Hi all,
I have a mac mini running maocosx 10.5 leopard I want to deploy a
django project on. My backend is MySQL, and I have it running as a 64-
bit app. Of course, apache2 is also running as...
|
by: zaheerusman |
last post by:
Hi,
I am using flex for interface, java for intermediate code and mysql for DB. My website contains videos so instead of uploading them on db, i have instead put a path in db and stored videos on...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |