kite111 Posted November 29, 2014 Share Posted November 29, 2014 (edited) Hello. I have a form with 5 textfields and 1 file field. It can already upload the file to a specified folder but I can't make it work when there are multiple textfields.It doesn't insert into the db table. How do you guys do it? <?phpif(isset($_FILES['filename'])){ $errors = array(); $file_name = $_FILES['filename']['name']; $file_size =$_FILES['filename']['size']; $file_tmp =$_FILES['filename']['tmp_name']; $file_type=$_FILES['filename']['type']; $file_ext=strtolower(end(explode('.',$_FILES['filename']['name'])));if(isset($_POST['name_sender'])){ $nameSender = $_POST['name_sender'];}if(isset($_POST['address'])){ $Address = $_POST['address'];}if(isset($_POST['contactno'])){ $contact_no = $_POST['contactno'];}if(isset($_POST['totalsent'])){ $total_sent = $_POST['totalsent'];}if(isset($_POST['datesent'])){ $date_sent = $_POST['datesent'];} $expensions= array("jpeg","jpg","png"); if(in_array($file_ext,$expensions)=== false){ $errors[]="extension not allowed, please choose a JPEG or PNG file."; } if($file_size > 2097152){ $errors[]='File size must be excately 2 MB'; } // if there are no errors... if (empty($errors)==true) { // upload the file... move_uploaded_file($file_tmp,"uploads/".$file_name); $servername = "localhost"; $username = "root"; $password = ""; $dbname = "admin"; // and create a new record in the database mysql_connect($servername, $username, $password) or die ('MySQL Not found // Could Not Connect.'); mysql_select_db("admin") or die(mysql_error()) ; mysql_query("INSERT INTO payment_form (name, address, contactno, totalsent, paymentdate, filename) VALUE ('$nameSender', '$Address', '$contact_no', '$total_sent', '$date_sent', $file_name')") ; echo "Success"; }else{ print_r($errors); }}?> i'm certain the my db table has the corresponding columns. sorry if it's a messy or a wrong way to code.i'm still in the stage of putting together codes that work... Edited November 29, 2014 by kite111 Link to comment Share on other sites More sharing options...
niche Posted November 29, 2014 Share Posted November 29, 2014 (edited) What errors do you get from your INSERT? Have you echoed each var to make sure they're what you expected? Also, try VALUES instead of VALUE Edited November 29, 2014 by niche Link to comment Share on other sites More sharing options...
kite111 Posted November 29, 2014 Author Share Posted November 29, 2014 What errors do you get from your INSERT? Have you echoed each var to make sure they're what you expected? Also, try VALUES instead of VALUE No i didn't echo the variables.got no errors.the file uploaded in the folder but the text fields didn't insert. oh and that was VALUES.the S just got erased from the editing.still doesn't insert in the db table. what else should I try? Link to comment Share on other sites More sharing options...
niche Posted November 29, 2014 Share Posted November 29, 2014 What's in the variables you need to insert? Link to comment Share on other sites More sharing options...
kite111 Posted November 29, 2014 Author Share Posted November 29, 2014 What's in the variables you need to insert? just some text like address, contact no, date. i wanna insert them to the columns in a db table. Link to comment Share on other sites More sharing options...
niche Posted November 29, 2014 Share Posted November 29, 2014 I don't see any error reporting in your INSERT. http://php.net/manual/en/function.mysql-error.php Link to comment Share on other sites More sharing options...
kite111 Posted November 29, 2014 Author Share Posted November 29, 2014 I don't see any error reporting in your INSERT. http://php.net/manual/en/function.mysql-error.php yeah. i have no idea why it doesn't insert in the db. Link to comment Share on other sites More sharing options...
niche Posted November 29, 2014 Share Posted November 29, 2014 put this at the end of your insert and you'll probably will know more: or die(mysql_error()) Link to comment Share on other sites More sharing options...
kite111 Posted November 29, 2014 Author Share Posted November 29, 2014 put this at the end of your insert and you'll probably will know more: or die(mysql_error()) tried this code. now i'm getting undefined index for every var in $_______ starting in if statement submit..what's wrong? if(isset($_FILES['filename'])){ $errors = array(); $file_name = $_FILES['filename']['name']; $file_size =$_FILES['filename']['size']; $file_tmp =$_FILES['filename']['tmp_name']; $file_type=$_FILES['filename']['type']; $file_ext=strtolower(end(explode('.',$_FILES['filename']['name'])));}if($_POST['submit']=="Submit"); { $nameSender = ($_POST['name_sender']); $Address = ($_POST['address']); $contact_no = ($_POST['contactno']); $total_sent = ($_POST['totalsent']); $date_sent = ($_POST['datesent']); $file_name = ($_POST['filename']); addData ($nameSender,$Address,$contact_no,$total_sent,$date_sent,$file_name); }function addData($nameSender, $Address, $contact_no, $total_sent, $date_sent, $file_name) { include ("dbinfo.php"); $sql = "INSERT INTO payment_form VALUES (null, '$nameSender', '$Address', '$contact_no', '$total_sent', '$date_sent', '$file_name')"; $result = mysql_query($sql) or die(mysql_error()); } Link to comment Share on other sites More sharing options...
niche Posted November 29, 2014 Share Posted November 29, 2014 What values do you get when you echo the values of each of these vars: $nameSender, $Address, $contact_no, $total_sent, $date_sent, $file_name Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now