mysql - php mysqli with insert and update queries -


this question exact duplicate of:

i creating feedback form users can write feedback , store in database using php mysqli without refreshing whole page . got success message without entered data can me ? asked yesterday same question php mysqli insert , update queries

feedback_form.php

<?php  session_start();   $login = ($_session['login']);    $userid = ($_session['user_id']);    $login_user = ($_session['username']);    $fname = ($_session['first_name']);    $lname = ($_session['last_name']);    $sessionaddres =($_session['address']);   ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>feedback page</title>     <script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>     <link href="style/stylesheet.css"rel="stylesheet" type="text/css"/>      <script type = "text/javascript">      $(function(){         $('#submit').click(function(){          $('#container').append('<img src = "images/loading.gif" alt="currently loading" id = "loading" />');                var comments = $('#comments').val();                $.ajax({                  url: 'feedback_process.php',                 type: 'post',                 data: {"comments": comments},                  success: function(result){                      $('#response').remove();                      $('#container').append('<p id = "response">' + result + '</p>');                      $('#loading').fadeout(500, function(){                          $(this).remove();                      });                  }               });                       return false;         });       });      </script>         </head> <?php require_once('header.php'); ?>  <body> <form action = "feedback_form.php" method = "post">   <div id = "container">             <h2><?php echo $login_user ?></h2>              <label = "comments">comments</label>           <textarea rows = "5"cols = "35" name = "comments" id = "comments"></textarea>           <br />   </div>    </form>        <input type = "submit" name = "submit" id = "submit" value = "send feedback" />     </body> </html>  

feedback_process.php

<?php  session_start();   $login = ($_session['login']);    $userid = ($_session['user_id']);    $login_user = ($_session['username']);    $fname = ($_session['first_name']);    $lname = ($_session['last_name']);    $sessionaddres =($_session['address']);   $conn = new mysqli('localhost', 'root', 'root', 'lam_el_chamel_db');    echo"<pre>";   print_r($_post);   echo"</pre>";    if(isset($_post['comments'])){    $comments = $_post['comments'];      $query = "insert feedback (feedback_text, user_name,) values(?,?)";    $stmt = $conn->stmt_init();   if($stmt->prepare($query))   {       $stmt->bind_param('ss', $comments, $login_user);      $stmt->execute();    }   $query2 = "update feedback set feedback_text = ?, user_name = ? user_name = ? ";   $stmt = $conn->stmt_init();   if($stmt->prepare($query2))   {      $stmt->bind_param('sss', $comments, $login_user, $login_user);      $stmt->execute();    }      if($stmt){    echo "thank .we in touch <br />";    }   else{    echo "there error. try again later.";    }    }  else    echo"it big error"; ?> 

first: don't ask questions 2 times. won't better or quicker answers because answer them twice...

the success message tells you've accessed file success (and not else). based on this, try run feedback_process.php alone (without involvement of feedback_form.php) "dummy" comment , "dummy" login_user. added output of "failed" when insert query did not work... (your code implemented success or not the update feedback-query (last one))

i hope code down below you...

<?php session_start();  $login = ($_session['login']);  $userid = ($_session['user_id']); $login_user = ($_session['username']); $fname = ($_session['first_name']); $lname = ($_session['last_name']); $sessionaddres =($_session['address']);   $conn = new mysqli('localhost', 'root', 'root', 'lam_el_chamel_db');  echo"<pre>"; print_r($_post); echo"</pre>";   //some dummys debugging $comments = 'this comments';  $login_user = 'foo';   $query = "insert feedback (feedback_text, user_name) values(?,?)";  $stmt = $conn->stmt_init(); if($stmt->prepare($query)) {     $stmt->bind_param('ss', $comments, $login_user);     $stmt->execute(); } else {     echo 'failed!'; }  $query2 = "update feedback set feedback_text = ?, user_name = ? user_name = ? "; $stmt = $conn->stmt_init(); if($stmt->prepare($query2)) {     $stmt->bind_param('sss', $comments, $login_user, $login_user);     $stmt->execute(); } else {     echo 'failed!'; }  if($stmt){     echo "thank .we in touch <br />"; } else {     echo "there error. try again later."; }    ?> 

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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -