Jump to content

writes to file needs to db


sandbudd

Recommended Posts

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);





?>


Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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')") ;



?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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')") ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.