javascript - New values don't update on db -


i want data database , change it, ajax when try change input ajax send same data on database.

    <script>     function showmore(str) {       var xhttp;       if (str.length == 0) {          document.getelementbyid("txtmore").innerhtml = "";         return;       }       xhttp = new xmlhttprequest();       xhttp.onreadystatechange = function() {         if (xhttp.readystate == 4 && xhttp.status == 200) {           document.getelementbyid("txtmore").innerhtml = xhttp.responsetext;         }       };       xhttp.open("get", "getmore.php?q="+str, true);       xhttp.send();        }     </script>     <body>      <div class="content">         <button id="edit">update</button>         <form action="">              <h3>last name:</h3><input type="text" id="txt1" onkeyup="showhint(this.value)">         </form>             <span id="txtmore"></span>     </div>       </body> <script type="text/javascript">  $('#edit').click(function(){      var id = $('#id_field').attr('value');     var name_field = $('#firstname').attr('value');     var last_field = $('#lastname').attr('value');     var telefone_field = $('#telefone').attr('value');     var email_field = $('#email').attr('value');     var check = $('#checkin').attr('value');      var datastring = 'id=' +id+ '&firstname=' +name_field+ '&lastname=' +last_field+ '&telefone=' +telefone_field+ '&email=' +email_field+ '&checkin=' +check;     alert(datastring);       $.ajax({         type: "get",         url: "edit_ajax.php",         data: datastring,         cache: false,         success: function(html)         {         $("#txthint").html('actualizado');         }     }); });  </script> 

and php file data database

<?php   ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(e_all);  $con = mysqli_connect('localhost','root','root','client_db'); if (!$con) {     die('could not connect: ' . mysqli_error($con)); }  $q = mysqli_real_escape_string($con, $_get['q']);  mysqli_select_db($con,"client_db"); $sql='select * user id = "'.$q.'" '; $result = mysqli_query($con,$sql);   while($row = mysqli_fetch_array($result)) {       echo'<form method="get" class="form_user">';     echo'<input type="hidden" name="id" id="id_field" value="'.$row['id'].'" class="inputform"><br><br>';     echo'primeiro nome<br>';     echo'<input type="text" name="firstname" id="firstname" value="'.$row['firstname'].'" class="inputform"><br><br>';     echo'ultimo nome<br>';     echo'<input type="text" name="lastname" id="lastname" value="'.$row['lastname'].'" class="inputform"><br><br>';     echo'telefone<br>';     echo'<input type="text" name="telefone" id="telefone" value="'.$row['telefone'].'" class="inputform"><br><br>';     echo'email<br>';     echo'<input type="text" name="email" id="email" value="'.$row['email'].'" class="inputform"><br><br>';     echo'<input type="checkbox" name="check" id="checkin" value="check">check-in<br><br>';     echo'</form>'; } mysqli_close($con); ?> 

thanks.

edit: problem isn't sql query values inside <input> if change values javascript read old values , send them php.

you're missing update request on db. right request select, no matter data sent server, you're not using it.

$sql='select * user id = "'.$q.'" '; $result = mysqli_query($con,$sql); 

you :

<?php  ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(e_all);  $con = mysqli_connect('localhost','root','root','client_db'); if (!$con) {    die('could not connect: ' . mysqli_error($con)); }  $q = mysqli_real_escape_string($con, $_get['q']);   $username = $get['firstname']; $lastname= $_get['lastname']  // every inputs form give  $sql = "update 'user' set 'firstname' = '$firstname','lastname' = '$lastname', etc...";   $result = mysqli_query($con,$sql);   mysqli_close($con); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -