Home  >  Article  >  Backend Development  >  Specific examples of adding and deleting operations using php and jquery_PHP tutorial

Specific examples of adding and deleting operations using php and jquery_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:18:10723browse

Use php in the background and reference jquery in the frontend to implement addition and deletion operations. The code is as follows:

Copy code The code is as follows:


header("Content-type: text/html; charset=utf-8");
//mysql_connect establishes a connection, mysql_close($link) closes the non-permanent connection, mysql_pconnect establishes a permanent connection
//mysql_error returns the mysql function error message, mysql_errno returns the mysql function error number
//mysql_set_charset sets the client character set, mysql_select_db selects the connection database
//mysql_query executes the query, mysql_num_rows returns the number of query records
//mysql_affected_rows returns the number of affected records, mysql_free_result releases the result set memory
//mysql_fetch_row returns enumerated array records, mysql_fetch_assoc returns associated array records
//mysql_fetch_array returns associated array or numeric array records, mysql_fetch_object returns object form records
//mysql_fetch_result obtains result set data
//%s string, %c is an ASCII character, %d is an integer, %u A symbolic number, %x a hexadecimal number
mysql_query("set charaset set utf-8");
$message=@$_POST["message"];
$shanchu=@$ _POST["shanchu"];
$top_title="PHP basic exercises";
$con=mysql_connect("localhost","root","");
//Connect to the database
mysql_set_charset ('utf-8',$con);
mysql_select_db("dbl",$con);
//Define database command query
$sql="select `message` ,`time`,` id` from message order by id desc limit 0,30";
//Execute database query
$rs=mysql_query($sql,$con);
$time=date('Y-m-d h:i :s',time());
//Get the number of items

$num_rows=mysql_num_rows($rs);//mysql_num_rows returns the number of query records
if (isset($_POST["submits"])) {
if(!$_POST["message"] ==null){
$queryinsert=sprintf("insert into message (message,time) values('%s','%s')",
$_POST['message'],$time) ;
mysql_query($queryinsert,$con);
}
if($_POST["message"]==null){
echo "";
}
header( "Location:http://localhost/table.php");
}

if(isset($_GET["ClearTd"]) && intval($_GET['ClearTd'])){
$querydelete="delete from message where id=".$_GET['ClearTd'] ;
mysql_query($querydelete,$con);
header("Location:http://localhost/table.php");
}
?>





    {
    ?>

  • echo $tiao;
    }?>
    Delete
  •  


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621690.htmlTechArticleUse php in the background and reference jquery in the frontend to implement addition and deletion operations. The code is as follows: Copy the code as follows: script type=" text/javascript" src="jquery-1.10.2.min.js"/script ?php header("...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn