<form id="submit" name ="submit" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >
<fieldset>
<legend>Enter Information</legend>
<label for="fname">Client First Name:</label>
<input id="fname" class="text" name="fname" size="20" type="text">
<label for="lname">Client Last Name:</label>
<input id="lname" class="text" name="lname" size="20" type="text">
<p id="f1_upload_process">Loading...<br/><img src="loader.gif" /><br/></p>
<p id="f1_upload_form" align="center"><br/>
<label>
<input name="myfile" id="myfile" type="file" size="30" />
</label>
</p>
<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
<input type="submit" name="submitBtn" class="sbtn" value="Add Client" />
</fieldset>
</form>
-------------------Javascript...........
$("form#submit").submit(function() {
// we want to store the values from the form input box, then send via ajax below
var fname = $('#fname').attr('value');
var lname = $('#lname').attr('value');
var myfile = $('#myfile').attr('value');
$.ajax({
type: "POST",
url: "save.php",
data: "fname="+ fname +"& lname="+ lname +"& myfile="+ myfile ,
success: function(){
}
});
return false;
});
------------Server Script-----------------
<?php
$hostname="localhost:3306";
$username="root";
$password="123";
$dbname="test_new";
$conn = mysql_connect($hostname,$username,$password) or die ('Not Connecting to the database');
@mysql_select_db($dbname) or die ('Not accessing table');
$uploaddir = "dat/";
$destination_path = $uploaddir . basename($_FILES['myfile']['name']);
$result = 0;
$target_path = $destination_path . basename( $_FILES['myfile']['name']);
if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
$result = 1;
}
sleep(1);
// CLIENT INFORMATION
$fname = htmlspecialchars(trim($_POST['fname']));
$lname = htmlspecialchars(trim($_POST['lname']));
$addClient = "INSERT INTO test (fname,lname) VALUES ('$fname','$lname')";
mysql_query($addClient) or die(mysql_error());
mysql_close($conn);
?>