PLEASE PLEASE PLEASE HELP!!, IN REAL BAD NEED!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamesxg1
Forum Newbie
Posts: 3
Joined: Tue Jan 20, 2009 10:48 am

PLEASE PLEASE PLEASE HELP!!, IN REAL BAD NEED!!

Post by jamesxg1 »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
 
 
Hiya People,
 
I'm In Real Bad Need OF Some Help Here Guy's.
 
You See I Have This PHP Upload Code For My Website And Basically The User Can Uplaod A File And Then It Will Add The File Name To A Row In My Database So I Can Syther Who Uploaded What,
 
Well What Is Happening Is That Once They Upload In The Database Where The Filename Goes It Is Only Going Like This (Eg. FileNameHere) With No Extension!,
 
I Was Wondering If Anyone, Litrully Anyone Could Help Me Make It So That It Save The File Name And The Extension! ?.
 
I Also Need It to Only Accept Image File's But That Isnt The Most Important At The Moment, I Really Need To Be Able To Get The Extension Added Aswell So If Anyone Can Help Please Mody The Code I Enter Below And PM It To Me.
 

Code: Select all

<?php session_start(); 
 
require("../db/db.php"); //include database file
require("../db/config.php"); //include configuration file
require("../db/util.php");
 
isloggedin();
accessneeded("C");
 
?>
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
 
//This gets all the other information from the form
$pic=($_FILES['photo']['name']);
 
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("share") or die(mysql_error()) ;
 
 
//Writes the information to the database
mysql_query("UPDATE users SET photo='$pic' WHERE photo=''") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
 
//Tells you if its all ok
echo "Your File ". basename( $_FILES['uploadedfile']['name']). " Has Been Uploaded!.";
}
else {
 
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.<br>Please Retry.";
}
?>
Thankyou So Much

James.


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: PLEASE PLEASE PLEASE HELP!!, IN REAL BAD NEED!!

Post by mattpointblank »

Your code on line 25 is the problem:

mysql_query("UPDATE users SET photo='$pic' WHERE photo=''") ;

You need to specify WHERE to update, eg, an ID number for the row you're updating. If you're not updating anything, but adding brand new info, rewrite it to:

mysql_query("INSERT INTO users (photo) VALUES ('$pic')";

Just a quick English tip as well: you don't need to capitalise the first letter of every word.
jamesxg1
Forum Newbie
Posts: 3
Joined: Tue Jan 20, 2009 10:48 am

Re: PLEASE PLEASE PLEASE HELP!!, IN REAL BAD NEED!!

Post by jamesxg1 »

mattpointblank wrote:Your code on line 25 is the problem:

mysql_query("UPDATE users SET photo='$pic' WHERE photo=''") ;

You need to specify WHERE to update, eg, an ID number for the row you're updating. If you're not updating anything, but adding brand new info, rewrite it to:

mysql_query("INSERT INTO users (photo) VALUES ('$pic')";

Just a quick English tip as well: you don't need to capitalise the first letter of every word.

Hiya,

Ok i am just going to try that now,

and is there any way i can add the varible $id so that it sythers into just the customers db row ?

and yes sorry lol, its a bad habbit i have (unknown why thoe) :)
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: PLEASE PLEASE PLEASE HELP!!, IN REAL BAD NEED!!

Post by mattpointblank »

You'd have to pass the user ID (or whatever it is) to the upload script - the most typical way is using a hidden form field which contains the value of the user ID, then when the form's submitted you can access it using $_POST['userID'].
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PLEASE PLEASE PLEASE HELP!!, IN REAL BAD NEED!!

Post by pickle »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply