corillo181 Posted May 7, 2006 Share Posted May 7, 2006 come on ppl every topic i post here get like 100 view and 0 answers.. i know someone must know something i ask simple questions..my new question is..i got a upload script right?so the scrib upload pics name and all that kind of pic stuff to a database right? follow along please..now want i want to do is if that user already got a picture in there when they upload a new one to subtitude the existin data wiht the new one..i know i can use update * from table where this and that = that..buthow do i put it on a upload scrip so when the person uplload the picture it does that..like if(userpicexist delete and update new one){ :-D} Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 7, 2006 Share Posted May 7, 2006 What you will want to do is upon upload you will want chekc the database first to see if the picture file name is already in the database and if so just use the UPDATE statement or if the file doesn't exists use the INSERT statement intsead. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted May 7, 2006 Author Share Posted May 7, 2006 why doesn't this one works..[code]<?phpsession_start();include 'db.php';$dir="userpic/";$actuser=$_SESSION['username'];if(isset($_POST['upload'])){$checkpic="SELECT username FROM userpic LIMIT 1";$query7=mysql_query($checkpic);while($checkuser=mysql_fetch_array($query7)){if($checkuser > 0){$query00=mysql_query("UPDATE userpic WHERE username='$actuser'");if(!query00){ echo"error";}}else{if ($_FILES['ulfile']['type']!="image/pjpeg") {echo"that kind of file is not permitted please only use jpg images.";exit();}if($_FILES['ulfile']['name']==""){echo"at least pic a picture man!";}$filename = $_FILES['ulfile']['name'];$tmpname = $_FILES['ulfile']['tmp_name'];$filesize = $_FILES['ulfile']['size'];$filetype = $_FILES['ulfile']['type'];$datetime = date('m-d-y h:i:s');$filepath = $dir . $filename;$result=copy($tmpname, $filepath);if(!$result){ echo " a problem occur";}$sql2=mysql_query("INSERT INTO userpic (name,username,datetime, size, type, path)VALUES('$filename','$actuser','$datetime','$filesize', '$filetype', '$filepath')") or die(mysql_error());header('Location: testphp/');}}}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.