FF2000 Posted February 24, 2016 Share Posted February 24, 2016 Hi, I am absolutly beginner in PHP, AJAX. In my Wordpress page I have following scene: 1. input box for name 2. combobox from country-> combo for cities depend of selected country Button for search in MySQL database After submit the database return result in a table (user, country, city, mobile, email, etc.) with 2 editable (mobile, email) input column and I put Update button in every row. My questions: 1) If I change one data on the editable column how can I know the number of row? 2) How can I run the update script without refresh page? Thanks for your answer. //UserInfo-modify.php <?php include_once('db.php'); $name = $_POST['nev']; $country = $_POST['megye']; $error = ""; $city = ""; $nodata = ""; $ID = 0; if (($country=="Bács-Kiskun")||($country=="Baranya")||($country=="Békés")||($country=="Borsod-Abaúj-Zemplén")||($country=="Csongrád")|| ($country=="Fejér")||($country=="Győr-Moson-Sopron")||($country=="Hajdú-Bihar")||($country=="Heves")||($country=="Jász-Nagykun-Szolnok")|| ($country=="Komárom-Esztergom")||($country=="Nógrád")||($country=="Pest")||($country=="Somogy")||($country=="Szabolcs-Szatmár-Bereg")|| ($country=="Tolna")||($country=="Vas")||($country=="Veszprém")||($country=="Zala")) { $city = $_POST['telepules']; if ($city=="---") $error = "-city"; } else { $error = "-country-city"; } mysqli_set_charset($conn,"utf8"); if (($city!="") AND ($name!="")) { $query = mysqli_query($conn,"SELECT nev,kor,megye,telepules,utca,mobil,email FROM `nrqadatr` WHERE nev='$name' AND telepules='$city'") or die("userinfo-modify-36 ".mysqli_error($conn));} else if (($city=="") AND ($name=="")) { $nodata = '1'; echo "Name and city = 0!"; } else if (($city!="") AND ($name=="")) { $query = mysqli_query($conn,"SELECT nev,kor,megye,telepules,utca,mobil,email FROM `nrqadatr` WHERE telepules='$city'") or die("userinfo-modify-45 ".mysqli_error($conn));} else if (($city=="") AND ($name!="")) {$query = mysqli_query($conn,"SELECT nev,kor,megye,telepules,utca,mobil,email FROM `nrqadatr` WHERE nev='$name'") or die("userinfo-modify-49 ".mysqli_error($conn));} if ($nodata!='1') { $rowcount=mysqli_num_rows($query); if ($rowcount>0) { echo '<table>'; $arrayofrows = array(); echo ' <table border=1> <tr style="background-color:#EFFBFB; font-weight:bold; border: 1px solid black;"> <td style="font-size:14px;">ID</td> <td style="font-size:14px;">Name</td> <td style="font-size:14px;">City</td> <td style="font-size:14px;">Age</td> <td style="font-size:14px;">Address</td> <td style="font-size:14px;">Mobil</td> <td style="font-size:14px;">E-mail</td> <td style="font-size:14px;">Operation</td> </tr>'; } else echo "\r\n<B><font color='red'>No data //my_script.js $("#sub").click( function() { $.post( $("#myForm").attr("action"), $("#myForm :input").serializeArray(), function(info) { $("#result").html(info); }); clearInput(); }); $("#myForm").submit( function() { return false; }); function clearInput() { $("#myForm :input").each( function() { $(this).val(''); }); } ."; while ($data = mysqli_fetch_array($query)) { $ID = $ID+1; $data_nev=$data["nev"]; echo ' <tr style="background-color:#EFFBFB; border: 1px solid black;"> <td><input type="radio" name="$kivalasztott_sor" value="AG"></td> <td style="font-size:14px;">'.$data["nev"].'</td> <td style="font-size:14px;">'.$data["telepules"].'</td> <td style="font-size:14px;">'.$data["kor"].'</td> <td style="font-size:14px;">'.$data["utca"].'</td> <td><input type="text" value='.$data["mobil"].'></td> <td><input type="text" value='.$data["email"].'></td> <td onclick="cellOnclick()"><a href="#" onclick="linkOnclick()" style="text-decoration: none;"> <input type=button value="UPDATE" myFunction(this); return false;"></button></td> </tr>'; } echo '</table>'; } unset($name); unset($kor); unset($country); unset($error); unset($city); unset($nodata); unset ($data_nev); ?> //Wordpress (main) page [insert_php] include '/select_list_cities.php'; [/insert_php] <html><head><meta charset="utf-8" /><script src="/ajax_select_cities.js" type="text/javascript"></script> </head><body><form id="myForm" action="/userInfo-modify.php" method="post"> Name*:<br><input type="text" name="nev"> <p> [insert_php] echo $re_html;[/insert_php]<br class="clear" /> <br class="clear" /> <button id="sub">Search</button> <br><br></form> <span id="result"></span> <div id="data"><?php echo $result; ?></div> <script type="text/javascript" src=" http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.1.min.js"></script> <script src="/my_script.js" type="text/javascript"></script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/300876-update-data-after-mysql-select/ Share on other sites More sharing options...
FF2000 Posted February 24, 2016 Author Share Posted February 24, 2016 //Userinfo-modify.php <?php include_once('db.php'); $name = $_POST['nev']; $country = $_POST['megye']; $error = ""; $city = ""; $nodata = ""; $ID = 0; if (($country=="Bács-Kiskun")||($country=="Baranya")||($country=="Békés")||($country=="Borsod-Abaúj-Zemplén")||($country=="Csongrád")|| ($country=="Fejér")||($country=="Győr-Moson-Sopron")||($country=="Hajdú-Bihar")||($country=="Heves")||($country=="Jász-Nagykun-Szolnok")|| ($country=="Komárom-Esztergom")||($country=="Nógrád")||($country=="Pest")||($country=="Somogy")||($country=="Szabolcs-Szatmár-Bereg")|| ($country=="Tolna")||($country=="Vas")||($country=="Veszprém")||($country=="Zala")) { $city = $_POST['telepules']; if ($city=="---") $error = "-city"; } else { $error = "-country-city"; } mysqli_set_charset($conn,"utf8"); if (($city!="") AND ($name!="")) { $query = mysqli_query($conn,"SELECT nev,kor,megye,telepules,utca,mobil,email FROM `nrqadatr` WHERE nev='$name' AND telepules='$city'") or die("userinfo-modify-36 ".mysqli_error($conn));} else if (($city=="") AND ($name=="")) { $nodata = '1'; echo "Name and city = 0!"; } else if (($city!="") AND ($name=="")) {$query = mysqli_query($conn,"SELECT nev,kor,megye,telepules,utca,mobil,email FROM `nrqadatr` WHERE telepules='$city'") or die("userinfo-modify-45 ".mysqli_error($conn));} else if (($city=="") AND ($name!="")) {$query = mysqli_query($conn,"SELECT nev,kor,megye,telepules,utca,mobil,email FROM `nrqadatr` WHERE nev='$name'") or die("userinfo-modify-49 ".mysqli_error($conn));} if ($nodata!='1') { $rowcount=mysqli_num_rows($query); if ($rowcount>0) { echo '<table>'; $arrayofrows = array(); echo ' <table border=1> <tr style="background-color:#EFFBFB; font-weight:bold; border: 1px solid black;"> <td style="font-size:14px;">ID</td> <td style="font-size:14px;">Name</td> <td style="font-size:14px;">City</td> <td style="font-size:14px;">Age</td> <td style="font-size:14px;">Address</td> <td style="font-size:14px;">Mobil</td> <td style="font-size:14px;">E-mail</td> <td style="font-size:14px;">Operation</td> </tr>'; } else echo "\r\n<B><font color='red'>A megadott feltételekkel nincsenek adatok."; while ($data = mysqli_fetch_array($query)) { $ID = $ID+1; $data_nev=$data["nev"]; echo ' <tr style="background-color:#EFFBFB; border: 1px solid black;"> <td><input type="radio" name="$kivalasztott_sor" value="AG"></td> <td style="font-size:14px;">'.$data["nev"].'</td> <td style="font-size:14px;">'.$data["telepules"].'</td> <td style="font-size:14px;">'.$data["kor"].'</td> <td style="font-size:14px;">'.$data["utca"].'</td> <td><input type="text" value='.$data["mobil"].'></td> <td><input type="text" value='.$data["email"].'></td> <td onclick="cellOnclick()"><a href="#" onclick="linkOnclick()" style="text-decoration: none;"> <input type=button value="UPDATE" myFunction(this); return false;"></button></td> </tr>'; } echo '</table>'; } unset($name); unset($kor); unset($country); unset($error); unset($city); unset($nodata); unset ($data_nev); ?> Quote Link to comment https://forums.phpfreaks.com/topic/300876-update-data-after-mysql-select/#findComment-1531419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.