簡體   English   中英

我如何在mysql中插入數據並單擊一個按鈕即可在php中同時檢索?

[英]how i can insert data in mysql and retrieve simulteneously in php on the click of one button?

實際上,我想向每個圖像發送評論,並且應該在單擊按鈕后立即顯示它。 我能夠插入和檢索評論,但是它需要刷新頁面,而我不想刷新....就像orkut.plz可以幫助我在php中實現新功能一樣...

謝謝大家............

insertimg.php

//________________________________________FOR INSERT COMMENT_____________________________________________________
if (isset($_POST['Submit'])) 
{
$sql = "INSERT INTO comment(imid, comm) values ('".mysql_real_escape_string(stripslashes($_REQUEST['imgId']))."', '".mysql_real_escape_string(stripslashes($_REQUEST['Comment']))."')";
//$sql = "INSERT INTO comment (com) VALUES ($_POST['Comment'])";
//$sql="UPDATE upload SET comm='$_REQUEST['Comment']'WHERE id='$_REQUEST['imgId']'";
if($result = mysql_query($sql ,$conn)) 
  {

     echo "submited:";

   }
else 
   {
    echo "<h1>problem </h1> ".mysql_error();
   }

} 

用於顯示注釋。

$page=$_GET["page"];
$sql = "select comm from comment where imid = '".$page."'";

$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
echo"Comments:";
echo "<br>";
echo "<br>";
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{

 //echo $row['comm'];
 echo "<textarea name=\"Comment\" style=\"background-color:#81F7BE;\">"; echo $row['comm']; echo "</textarea>";
 //echo "<font>";
 echo "<br>";
 echo "<br>";
}   
mysql_close($conn);

?>

您可以使用AJAX解決它。 您可以使用類似jQuery Ajax庫的工具。

$.ajax({
   type: "POST",
   url: "inserting.php",
   data: "imid=1&comm=Hi",
   success: function(msg){
     alert( "Ajax Response: " + msg );
   }
 });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM