0

My test.php page is as under:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h3>Setting</h3>
<p>Name:<input type="text" id="updatetherone1"/></p>
<p>Email:<input type="text" id="updateotherone2"/></p>
<p>
<input id="updateone" type="button" value="Save"/>
<span id="updateotherotherone"></span>
</p>

<script src="js/jquery.js"></script>
<script src="js/ajax.js"></script> 
</body>
</html>

My ini.php page is as under:

<?php
session_start();
$_SESSION['state'] ='2';
$conn=new mysqli('localhost','root','','people');

?>

My test1.php page is as under:

<?php
include 'ini.php';

if (isset($_POST['name'], $POST['email'])){
$name = mysqli_real_escape_string(htmlentities($POST['name']));
$email = mysqli_real_escape_string(htmlentities($POST['email']));

$update = mysqli_query("UPDATE state SET Name='$name', email='$email' WHERE Id=".$_SESSION['state']);

if($update === true){
echo 'Setting have been updated.';
}else if ($update === false){
echo 'There was an error updating your setting.';
}
}
?>

My ajax.js page is as under:

$('[id=updateone]').click(function(){
var name=$('[id=updateotherone1]').val();
var email=$('[id=updateotherone2]').val();
$('[id=updateotherotherone]').text('Loading...');

$.post('test1.php',{name:name,email:email},function(data){
$('[id=updateotherotherone]').text(data);
});
});

Ultimately code is not working nor do it is displaying any error, I suspect there is something wrong with test1.php page, can anybody guide please:

2
  • Ugh, your code isn't very structured... Why haven't you put your form elements in a "form" element in your HTML? If JavaScript is disabled your form will never work. You've over complicated a very simple AJAX form. Also, I would read up on jQuery form submitting, there are many tutorials on the Internet...
    – Kinnectus
    Jan 1, 2015 at 22:39
  • Use a "form" and you could quite easily write a jQuery function to post the form to the action URL and receive/process the response.
    – Kinnectus
    Jan 1, 2015 at 22:44

1 Answer 1

0

Please read the comment from Big Chris

you also should try to set the variable Id='$_SESSION[\'state\']' in quotes and because you use quotes inside this variable you have to use backslash so php can set the quotes correctly without interrupting the variable

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .