Following is my code and I'm not able to write insert query and upload file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.js"> </script>
<script src="http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js"></script>
<!-- This JavaScript snippet activates those tabs -->
<script type="text/javascript">

$(function() {	
	$("div.tabs").tabs("div.panes > div");	
});
</script>

<script type="text/javascript">
$(document).ready(function(){		
	$('#share').click(function(){		
		var status=$("#content").val();
		var file=$("#filecontent").val().replace(/C:\\fakepath\\/i, '');		
		var DATA = 'status=' + status + '&file=' + file + '&share=true';		
		$.ajax({
		type: "POST",
		url: "insert.php",		
		data: DATA,
		success: function() {
		alert (DATA);
		}
	  });	  
	  return false;	
	});
});
</script>
<style type="text/css">
li
{
display: inline;
list-style-type: none;
padding-right: 20px;
}
</style>
</head>

<body>
<div class="tabs">
	<!-- the tabs -->
	<ul>
		<li><a href="#">Status</a></li>
		<li><a href="#">Photo</a></li>
		<li><a href="#">Question</a></li>
	</ul>
</div>

<!-- tab "panes" -->
<div class="panes"  >
	<div><textarea class="input" name="status" id="content" >So what's on your mind?</textarea></div>
	<div><input type="file"  name="file" id="filecontent"/></div>	
	<div>Ask question<input type="text"  name="question" id="question"/></div>
</div>
<br />
<div class="button_outside" id="share">
    <div class="button_inside">Share</div>
</div>
</body>
</html>

Recommended Answers

where are your form tags?

Jump to Post

You're trying to upload a file - I didn't know that you could do this without the enctype attribute of the form tag. If you can, accept my apologies.

You don't show your 'insert.php' code, which I assume will contain the insert query.

You're passing 3 post vars: …

Jump to Post

All 6 Replies

set the correct headers to send a file using ajax.

Member Avatar

where are your form tags?

'#share' function submit input and textarea fields without form tags.
Can u help me to write insert query?

where are your form tags?

Member Avatar

Well that may be so, but it's wrong wrt HTML.

Why?

Well that may be so, but it's wrong wrt HTML.

Member Avatar

You're trying to upload a file - I didn't know that you could do this without the enctype attribute of the form tag. If you can, accept my apologies.

You don't show your 'insert.php' code, which I assume will contain the insert query.

You're passing 3 post vars: share/filename/status

Accept these with $_POST... etc.
Clean them and prepare them for use in sql:
Include your mysql connection details
run the query

INSERT INTO table SET `share`='$cleanshare',`filename`='$cleanfile',`status`='$cleanstatus'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.