sandbudd Posted July 2, 2008 Share Posted July 2, 2008 This code pulls the info from the form with multiple uploads and writes to a file on the server. How would I go about making it write to a mysql database. I can get it to write to the database but the uploads wont point to the file? Any help would be appreciated. <?php error_reporting(0); session_start(); $Domain="http://".$_SERVER['HTTP_HOST']; $fname=$_POST['fname']; $company=$_POST['company']; $address=$_POST['address']; $city=$_POST['city']; $zip=$_POST['zip']; $email=$_POST['email']; $phone=$_POST['phone']; $fax=$_POST['fax']; $type2=$_POST['type2']; $type3=$_POST['type3']; $burnishing=$_POST['burnish']; $chromate=$_POST['chromate']; $hex=$_POST['hex']; $impregnation=$_POST['impregnation']; $impregnation=$_POST['strip']; $part_number=$_POST['part_number']; $part_description=$_POST['part_description']; $specifications=$_POST['specifications']; $repeat=$_POST['repeat']; $internet_search=$_POST['internet_search']; $internet_directory=$_POST['internet_directory']; $referral=$_POST['referral']; $yellow_pages=$_POST['yellow_pages']; $trade_show=$_POST['trade_show']; $other=$_POST['other']; $notes=$_POST['notes']; $cdir="rfq"; $save_path="uploads/"; $date = date("F j, Y, g:i a"); $file = $_FILES['userfile']; $k = count($file['name']); for($i=0;$i< $k ;$i++) { if(isset($save_path) && $save_path!="") { $random_digit=rand(0000,9999999); $name = split('/',$file['name'][$i]); $name = str_replace("\\","",$name); $name = str_replace("'","",$name); $name = str_replace("","_",$name); $name = str_replace(" ","_",$name); $name = str_replace(".",$random_digit.".",$name); if(move_uploaded_file($file['tmp_name'][$i], $save_path . $name[count($name)-1])) { //// download the file///// $finalfile.="<li><a href='".$Domain."/".$cdir."/download.php?f=".$name[count($name)-1]."'>".$name[count($name)-1]."</a></li>"; $list_files.="<li>".$name[count($name)-1]."</li>"; } } } ///message in the mail////// $msg="-- This is the Customer's information -- <br>Full Name: $fname <br>Company: $company <br>Address: $address <br>City: $city <br>State: $State <br>Zip: $zip <br>Email: <a href='mailto:$email'>$email<a> <br>Phone Number: $phone <br>Fax Number: $fax <br>Process Requested? <br>$type2 $type3 $burnish $chromate $hex $impregnation $strip <br>Part Number: $part_number <br>Part Description: $part_description <br>Alloy: $alloy <br>Quantity: $quantity <br>Specifications: $specifications <br>Color: $color <br>How did you hear about us? <br>Repeat: $repeat <br>Internet Search: $internet_search <br>Internet Directory: $internet_directory <br>Referral: $referral <br>Yellow Pages: $yellow_pages <br>Trade Show: $trade_show <br>Other: $other <br>Notes: $notes <br><br>Attached files: $finalfile"; $msg2=" <br>----------------------------------------------------- <br> <br>-- Clients information Submitted $date --<br> <br>Full Name: $fname <br>Company: $company <br>Address: $address <br>City: $city <br>State: $State <br>Zip: $zip <br>Email Address: <a href='mailto:$email'>$email<a> <br>Phone Number: $phone <br>Fax Number: $fax <br>Process Requested? $type2 $type3 $burnish $chromate $hex $impregnation $strip <br>Part Number: $part_number <br>Part Description: $part_description <br>Alloy: $alloy <br>Quantity: $quantity <br>Specifications: $specifications <br>Color: $color <br>How did you hear about us? <br>Repeat: $repeat <br>Internet Search: $internet_search <br>Internet Directory: $internet_directory <br>Referral: $referral <br>Yellow Pages: $yellow_pages <br>Trade Show: $trade_show <br>Other: $other <br>Notes: $notes <br><br>Attached files: <br>$finalfile <br>"; ///email address//// $to = "dan@sandbudd.com"; ///Subject Title $subject="New Message"; $headers = "From: $email\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1"; //mail Function////// mail($to,$subject,$msg,$headers); $fh = fopen("email.php", "a"); fwrite($fh, $msg2); fclose($fh); ?> Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 That is a very broad question. Do you have a mysql database set up? Do you need to know the sql or how to use mysql? Here is the getting started mysql tutorial from their website: http://dev.mysql.com/tech-resources/articles/mysql_intro.html Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 2, 2008 Share Posted July 2, 2008 well heres the logic anyways.. FILL OUT FORM COLLECT VALUES-ASSIGN TO VARIABLES SUBMIT VALUES TO DATABASE(one of these values should be link to file) when you need to display the link to the file SNATCH THE LINK FROM DATABASE PLUG VALUE INTO ANCHOR <a href='".$YOURLINK."'>".$FILENAME."</a> Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 2, 2008 Share Posted July 2, 2008 That is a very broad question. Do you have a mysql database set up? Do you need to know the sql or how to use mysql? Here is the getting started mysql tutorial from their website: http://dev.mysql.com/tech-resources/articles/mysql_intro.html he did say he could write the values to the database.. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 2, 2008 Author Share Posted July 2, 2008 I do have the database set up and it does write to the database all except the uploaded files? Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 Oh yea, sorry. I read that as "I can get it to write to the file..." I didn't see any mysql functions in the code. Anyway, are you trying to write the binary data to the database or just the file path or name? Can you explain how your table is set up and show your SQL? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 2, 2008 Author Share Posted July 2, 2008 Here is the database code which I know it not right. Again every thing goes to the database except the file upload link. I know its sloppy but I have been working on this for days and it is killing me. <?php error_reporting(0); $Domain="http://".$_SERVER['HTTP_HOST']; $file = $_FILES['userfile']; $k = count($file['name']); for($i=0;$i< $k ;$i++) { if(isset($save_path) && $save_path!="") { $random_digit=rand(0000,9999999); $name = split('/',$file['name'][$i]); $name = str_replace("\\","",$name); $name = str_replace("'","",$name); $name = str_replace("","_",$name); $name = str_replace(" ","_",$name); $name = str_replace(".",$random_digit.".",$name); if(move_uploaded_file($file['tmp_name'][$i], $save_path . $name[count($name)-1])) { //// download the file///// $finalfile.="<li><a href='".$Domain."/".$cdir."/download.php?f=".$name[count($name)-1]."'>".$name[count($name)-1]."</a></li>"; $list_files.="<li>".$name[count($name)-1]."</li>"; } } } ?> <style type="text/css"> <!-- .style3 { font-size: 18px; font-family: Arial, Helvetica, sans-serif; } --> </style> <p></p> <?php //This gets all the other information from the form $name=$_POST['name']; $company=$_POST['company']; $address=$_POST['address']; $city=$_POST['city']; $state=$_POST['state']; $zip=$_POST['zip']; $email=$_POST['email']; $phone=$_POST['phone']; $fax=$_POST['fax']; $type2=$_POST['type2']; $type3=$_POST['type3']; $burnish=$_POST['burnish']; $chromate=$_POST['chromate']; $hex=$_POST['hex']; $impregnation=$_POST['impregnation']; $strip=$_POST['strip']; $part=$_POST['part']; $description=$_POST['description']; $alloy=$_POST['alloy']; $quantity=$_POST['quantity']; $spec=$_POST['spec']; $color=$_POST['color']; $repeat_customer=$_POST['repeat_customer']; $isearch=$_POST['isearch']; $idir=$_POST['idir']; $referral=$_POST['referral']; $yellow=$_POST['yellow']; $trade=$_POST['trade']; $other=$_POST['other']; $notes=$_POST['notes']; $finalfile=($_FILES['finalfile']['name']); // Connects to your Database $db_host = 'm; $db_user = ''; $db_pwd = ''; $database = ''; $table = 'e'; ini_set('error_reporting',E_ALL); if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); //Writes the information to the database mysql_query("INSERT INTO `contacts` VALUES ('$id', '$name', '$company', '$address', '$city', '$state', '$zip', '$email', '$phone', '$fax', '$type2', '$type3', '$burnish', '$chromate', '$hex', '$impregnation', '$strip', '$part', '$description', '$alloy', '$quantity', '$spec', '$color', '$repeat_customer', '$isearch', '$idir', '$referral', '$yellow', '$trade', '$other', '$notes', '$pic')") ; ?> Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 2, 2008 Author Share Posted July 2, 2008 here is the database Field Type Collation Attributes Null Default Extra Action id int(11) No auto_increment Browse distinct values Change Drop Primary Unique Index Fulltext name varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext company varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext address varchar(200) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext city varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext state varchar(25) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext zip varchar(10) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext email varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext phone varchar(15) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext fax varchar(15) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext type2 varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext type3 varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext burnish varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext chromate varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext hex varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext impregnation varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext strip varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext part varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext description varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext alloy varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext quantity varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext spec varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext color varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext repeat_customer varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext isearch varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext idir varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext referral varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext yellow varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext trade varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext other text latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext notes text latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext finalfile varchar(30) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 You are using the variable $pic in the spot where you are inserting the file name and there is no $pic variable defined in the code you showed. My guess is that you want that to be $finalfile. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 2, 2008 Author Share Posted July 2, 2008 changed to this still wont work? //Writes the information to the database mysql_query("INSERT INTO `contacts` VALUES ('$id', '$name', '$company', '$address', '$city', '$state', '$zip', '$email', '$phone', '$fax', '$type2', '$type3', '$burnish', '$chromate', '$hex', '$impregnation', '$strip', '$part', '$description', '$alloy', '$quantity', '$spec', '$color', '$repeat_customer', '$isearch', '$idir', '$referral', '$yellow', '$trade', '$other', '$notes', '$finalfile')") ; Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 What actually gets put into the database in that column? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 2, 2008 Author Share Posted July 2, 2008 trying to get the links of the file that was written to the uploads folder. 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.