deansaddigh Posted June 19, 2009 Share Posted June 19, 2009 Hi guys, basically im making an upload form for user avatars. I am adding the avatar details to the user table. my php code doesnt do anything and im not really sure why. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="icon" type="image/gif" href="../site icon/animated_favicon1.gif"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Lifey/Home</title> <!-- Css style sheet with form part 1--> <link href="../css/layout.css" rel="stylesheet" type="text/css" /> <?php /********************Db connection***********************************/ include '../db/connection.php'; ?> </head> <body> <!--top links --> <?php include "../includes/homepage_top_nav.php"; ?> <!-- Container div--> <div id="container"> <!-- puffin image--> <div id="puffin_image"></div> <!-- absolute positioned time and date--> <div id="dt"> <?php echo date("l, F dS Y g:i:s a ") ?> </div> <!-- Logo --> <div id="logo"></div> <!--contents--> <div id="contents"> <form method="post" enctype="multipart/form-data"> <p> Please use this form to upload your avatar</p> <fieldset class="login"> <legend>Avatar Upload</legend> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </fieldset> </form> <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include 'library/config.php'; include 'library/opendb.php'; $query = "INSERT INTO upload (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); include 'library/closedb.php'; echo "<br>File $fileName uploaded<br>"; } ?> </div> <?php include"../includes/homepage_footer_links.php"; ?> <!-- End Container div--> </div> </body> </html> Any one have any ideas its prob really simple but i cant for the life of me figure it out. Also can anyone say if this is the best way to do this, as i got this code from a website Quote Link to comment Share on other sites More sharing options...
joel24 Posted June 19, 2009 Share Posted June 19, 2009 your form doesn't have an action...? i.e. it should be something like (if the data should be posted to itself) <form method="post" enctype="multipart/form-data" action="<?php echo basename($_SERVER['PHP_SELF']); ?>"> otherwise set action="rarqara.php" to whatever page the data should b posted to. and theres no submit button?! Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted June 19, 2009 Author Share Posted June 19, 2009 thanks very much for your help, greatly appreciated Quote Link to comment Share on other sites More sharing options...
EchoFool Posted June 19, 2009 Share Posted June 19, 2009 Click topic solved if this issue is done please Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted June 19, 2009 Author Share Posted June 19, 2009 oopsy sorry , i have done it now 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.