liamk Posted May 24, 2012 Share Posted May 24, 2012 <?php ob_start(); if(isset($_POST['add'])) { $target = "admin/stockin/files/"; $target = $target . basename( isset($_FILES['file']['name'])); $brands= $_POST['brands']; $season= $_POST['season']; $file= isset($_FILES['file']['name']); $branch = $_POST['branch']; $auth = $_POST['auth']; $date = $_POST['date']; $status = $_POST['status']; $query = mysql_query("INSERT INTO stockin (brands, season, `file`, branch, auth, date, status) VALUES('$brands','$season','$file','$branch','$auth','$date','$status')") or die(mysql_error); if(move_uploaded_file(isset($_FILES['file']['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."; } //echo "<meta http-equiv='refresh' content='0;url=page.php?id=stockin' />"; } else { ?> <fieldset> <legend>Post Request</legend> <form method='POST'> <label>Brand:</label> <?php $sql = "SELECT brands FROM brands ORDER BY brands"; $result = mysql_query($sql); echo "<select name='brands'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['brands'] . "'>" . $row['brands'] . "</option>"; } echo "</select>"; ?> <br /> <label>Season:</label> <?php $sql = "SELECT season FROM season"; $result = mysql_query($sql); echo "<select name='season'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['season'] . "'>" . $row['season'] . "</option>"; } echo "</select>"; ?> <br /> <label>File:</label> <input type='file' size='35' maxlength='255' name='file' /><br /> <label>Branch:</label> <?php $sql = "SELECT branch FROM branch"; $result = mysql_query($sql); echo "<select name='branch'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['branch'] . "'>" . $row['branch'] . "</option>"; } echo "</select>"; ?> <br /> <?php $query = "SELECT * FROM users WHERE username='$usr'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "<label>Authorized By:</label> <input readonly='readonly' type='text' size='35' maxlength='25' name='auth' value='" . $row['name'] . "' /><br />"; } ?> <label>Date:</label> <input readonly="readonly"type='text' name='date' size='35' value='<?php echo date("D M d, Y G:i a"); ?>' /><br /> <label>Status:</label> <select name='status'> <option value='pending'>Pending</option> <option value='ready'>Ready</option> <option value='outofstock'>Out of Stock</option> </select> <br /> <input name='add' type='submit' value='Post Request' /> </form> </fieldset> <? } ?> There is the code and i dont understand why it wont upload. It returns with the error message cant upload file or whatever it says. Help would greatly appreciated Liam. Quote Link to comment https://forums.phpfreaks.com/topic/263047-inserting-data-in-mysql-database-with-_file-error/ Share on other sites More sharing options...
PravinS Posted May 24, 2012 Share Posted May 24, 2012 To upload files we have use enctype="multipart/form-data" form attribute in form tag Quote Link to comment https://forums.phpfreaks.com/topic/263047-inserting-data-in-mysql-database-with-_file-error/#findComment-1348265 Share on other sites More sharing options...
liamk Posted May 24, 2012 Author Share Posted May 24, 2012 Got the following error Warning: move_uploaded_file() expects exactly 2 parameters, 1 given in /home/viisual/public_html/stock/stockin/main.php on line 60 Sorry, there was a problem uploading your file. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/263047-inserting-data-in-mysql-database-with-_file-error/#findComment-1348281 Share on other sites More sharing options...
Pikachu2000 Posted May 24, 2012 Share Posted May 24, 2012 Right. You're only passing the value returned from isset($_FILES['file']['tmp_name'], $target) to move_uploaded_file(), which will be a boolean TRUE/FALSE value. You're using isset() in the wrong manner, and have too many things enclosed in its parentheses, too. if(move_uploaded_file(isset($_FILES['file']['tmp_name'], $target))) Quote Link to comment https://forums.phpfreaks.com/topic/263047-inserting-data-in-mysql-database-with-_file-error/#findComment-1348291 Share on other sites More sharing options...
liamk Posted May 24, 2012 Author Share Posted May 24, 2012 How would i go about amending this issue, now i have no errors but getting the error Upload Failed. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/263047-inserting-data-in-mysql-database-with-_file-error/#findComment-1348295 Share on other sites More sharing options...
liamk Posted May 24, 2012 Author Share Posted May 24, 2012 All fixed and working just had a look at the code and what you said and amended it. Quote Link to comment https://forums.phpfreaks.com/topic/263047-inserting-data-in-mysql-database-with-_file-error/#findComment-1348317 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.