Jump to content

Update data after MySQL select


FF2000

Recommended Posts

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>

php_search.jpg

 

Link to comment
Share on other sites


//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);
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.