Using a PHP POST form inside javascript - jquery .load()


I'm using a fairly standard HTML/PHP form to update tables in a MYSQL database. When I load the form into a web browser directly it works just fine. When I try loading the form through javascript (via a larger website) the forms displays but doesn't do anything. When i click the submit button nothing happens - and no errors are generated anywhere I can see. Can anyone shed some light on this?

this.display_admin_table_header = function () {

    current_pane.send_get_admin_table_data = this.send_get_admin_table_data;
    $('#stat_table').load('form2.php');  //<--form i'm loading

Here is the web form:


$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'my_db';
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

if(! $conn )
  die('Could not connect: ' . mysql_error());

$node = $_POST['label'];
$mode  = $_POST['mode'];
$department = $_POST['department'];
$ip = $_POST['ip'];
$username = $_POST['username'];
$password = $_POST['password'];
$db = $_POST['db'];

$sql = "INSERT into device ".
   "SET label = '$node' , ".
  # "SET mode = $mode ".
  # "SET department = $department ".
  # "SET ip = $ip ".
  # "SET username = $username ".
  # "SET password = $password ".
   "db = $db ";

error_log(" $sql \n");
if(! mysqli_query( $conn,$sql ))
 die('Could not update data: ' . mysqli_error($conn));
echo "Updated data successfully\n";
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
     <td width="100">Node </td>
  <td><input name="label" type="text" id="label"> </td>
     <td width="100">Site-Bucket </td>
     <td><input name="department" type="text" id="department"> </td>
     <td width="100">Mode </td>
      <td><input name="mode" type="radio" id="mode" value="1">Cmode <br>
     <input name="mode" type="radio" id="mode" value="2">7mode<br> </td>
     <td width="100">Node Man. IP </td>
     <td><input name="ip" type="text" id="ip"> </td>
    <td width="100">Username </td>
    <td><input name="username" type="text" id="username"> </td>
    <td width="100">Password </td>
    <td><input name="password" type="text" id="password"> </td>
      <td width="100">DB in use?</td>
      <td><input name="db" type="radio" id="db" value=1>Yes <br>
      <input name="db" type="radio" id="db" value=0>No <br> </td>
       <td width="100"> </td>
<td> </td>
       <td width="100"> </td>
<input name="update" type="submit" id="update" value="Update">



People are also looking for solutions to the problem: php - IE8 Password field showing entered value instead of showing asterisks


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.