Can't get html to run in php file called by AJAX
hi,
I am writing a Revise Data program for my database. I am passing the field name of data to be changed to 'changeData.php'. When this data is received by 'changeData.php' I want to use a form inside 'changeData.php' to revise the data and then to update the database.
If I call changeData.php from the command line it works fine.
(firefox mydb.com/db/changeData.php) The form appears in workable manner.
If I take the HTML code out of changeData it works fine. It will update data as fed by a variable for testing purposes.
Appreciate knowing a fix for this problem. CODE and results are below.
Thanks in advance
R
I am calling changeData.php file from fields.php with ajax as follows:
$('.rowdata').click(function () {
col=$(this).text();
$.ajax({
type: "GET",
url: "changeData.php",
data: { "col":col},
datatype: "text",
success: showChangedData
}); // ajax
function showChangedData(data) {
alert("this is returned data: "+data);
window.location="fields.php";
$('.retdata').toggleClass('msg');
} // showCh
}); // rowdata
This returns:
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
result ok:
Here is my php code:
<?php
$hostname='localhost';
$username='r';
$password='r';
$database='db';
$table='per';
$fields=array();
$field=$_GET['col'];
$ret='ZG64526E - FL';
$msg="Data Sucessfully Changed";
?>
<html> ]
// This test HTML doesn't work. Actual HTML is much longer.
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
<?php
$cxn = mysqli_connect($hostname,$username,$password,$database)
or die("line 34 - Couldn't connect to server");
$query = "UPDATE {$table} SET {$field} = '{$ret}';";
$result = mysqli_query($cxn,$query);
if($result) {
echo "result ok:";
}
?>