Title: PHP form within jQuery
Tags: php;jquery;html
Question: I have a PHP form posting to a database fine. Have included it within a jQuery web page. The form is not posting to the database. Below is the code for the webpage and the PHP file. The form behaves fine when it the javascript files are not included.
<link href="jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"/&gt;
<script src="jquery-1.6.4.min.js" type="text/javascript"&gt;</script&gt;
<script src="jquery.mobile-1.0.min.js" type="text/javascript"&gt;</script&gt;
<meta name="viewport" content="width=device-width; initial-scale= -3.0; maximum-scale=0.0; user-scalable=0;"/&gt;
<meta name="format-detection" content="telephone=no" /&gt;
</head&gt;
<body&gt;
<table border="1"&gt;
<tr&gt;
<td align="center"&gt;Form Input Employees Data</td&gt;
</tr&gt;
<tr&gt;
<td&gt;
<table&gt;
<?php include 'input.php'; ?&gt;
<form method="post" action="input.php"&gt;
<tr&gt;
<td&gt;Date</td&gt;
<td&gt;<input type="date" name="date" size="20"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Name</td&gt;
<td&gt;<input type="text" name="name" size="20"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Address</td&gt;
<td&gt;<input type="text" name="address" size="40"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Phone</td&gt;
<td&gt;<input type="tel" name="phone" size="20"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Email</td&gt;
<td&gt;<input type="email" name="email" size="20"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Problem</td&gt;
<td&gt;<input type="text" name="problem" size="40"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Description</td&gt;
<td&gt;<textarea cols="40" rows="5" name="description"&gt;</textarea&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Time Arrived</td&gt;
<td&gt;<input type="time" name="timeArrived" size="20"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Time Departed</td&gt;
<td&gt;<input type="time" name="timeDeparted" size="20"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Cost of Material</td&gt;
<td&gt;<input type="number" name="material" size="40"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Total Job Cost</td&gt;
<td&gt;<input type="number" name="total" size="40"&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Completed Yes/No</td&gt;
<td&gt;<input type="checkbox" name="completed" value="Yes"&gt;Yes<br&gt;
<input type="checkbox" name="completed" value="No"&gt;No
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;Reason fo Incompletion</td&gt;
<td&gt;<textarea cols="40" rows="5" name="incomplete"&gt;</textarea&gt;
</td&gt;
</tr&gt;
<tr&gt;
<td&gt;</td&gt;
<td align="right"&gt;<input type="submit" name="submit" value="Sent"&gt;</td&gt;
</tr&gt;
</form&gt;
</table&gt;
</td&gt;
</tr&gt;
</table&gt;
</body&gt;
</html&gt;
PHP File:
mysql_connect("localhost","$user","$password");//database connection
mysql_select_db("&amp;database");
$order = "INSERT INTO table1
(date, first_name, address, phone, email, problem, description, time_arrived, time_departed, cost_material, total, completed, reason)
VALUES
('$_POST[date]', '$_POST[name]', '$_POST[address]', '$_POST[phone]','$_POST[email]','$_POST[problem]','$_POST[description]','$_POST[timeArrived]','$_POST[timeDeparted]',
'$_POST[material]','$_POST[total]','$_POST[completed]','$_POST[incomplete]')";
$result = mysql_query($order);  //order executes
if($result){
echo("<br&gt;Input data is succeed");
} else{
echo("<br&gt;Input data is fail");
Comment: **&database** sure about that ?

Comment: Apologies. Just changed the database name for posting here. On actual it is correct. @tinyByte it is something I want to look into... Security is pretty much null at this stage! Cheers for the input!

Comment: ever heard of **sql injections** ?


Here is another answer: I think the code where you include the script is right, I don't underestand what do you wanna do when you say that: "the javascript files are not included" but the code to include the script is right, that code should work unless you have a problem with PATH.
Comment for this answer: comment, not an answer

Here is another answer: First, I'd rewrite the php code to use mysqli or PDO and prepared statements. As it is right now, it's very vulnerable to sql injections.
Next, I'd revise the javascript code using to actually submit the form.
Finally, I'd either fire up a PHP debugger or print out the _POST array to make sure that the values are being passed correctly.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:02/09/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><jquery><html>', 'Title': 'PHP form within jQuery', 'ViewCount': 64, 'id': 21664297, 'user_AboutMe': None, 'user_AccountId': 3991826.0, 'user_DisplayName': 'user3290504', 'user_Reputation': 1.0, 'user_Views': 2.0, 'user_id': 3290504.0}}