Php lists data and then deletes data using js.

Source: Internet
Author: User

Php lists data and then deletes data using js.

<? Php
Include ("../inc. php ");
Islogin ();
$ Db = new Db ();
?>
<! 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 = gb2312"/>
<Title> add a city category </title>
<! -- At: jimmy email: mailangel123@163.com -->

<LINK href = "/themes/default/css/admin.css" rel = stylesheet>

<Style type = "text/css">
<! --
. STYLE2 {color: #666666}
-->
</Style>
</Head>
<Body>

<Table class = "table_list">
<Form action = "" name = "myfm" id = "myfm">
<Caption> <font class = "red">
{<? = PostGet ('cname') ;?>} </Font> region Management
</Caption>
 
<Tr>
<Th width = "32%"> region name </th>
<Th width = "43%"> sorting position </th>
<Th width = "25%"> & nbsp; </th>
</Tr>
<? Php
$ Id = PostGet ('aid ');
If (! Is_numeric ($ id ))
  {
Exit;
  }
$ Query = $ Db-> query ("Select upid, cntitle, orderid, id from cn_loupan_city where upid = '$ ID' order by orderid asc ");
If ($ Db-> rows ($ query ))
  {
$ Row = $ Db-> fetch ($ query, 0 );
   
Foreach ($ row as $ array =>$ _ v)
   {
?>
 
<Tr>
<Td class = "align_c"> <label>
<Input id = "c _ <? = $ _ V [3]?> "Type =" text "size =" 30 "value =" <? = $ _ V [1]?> "/>
</Label> </td>
<Td class = "align_c"> <label>
<Input id = "s _ <? = $ _ V [3]?> "Type =" text "size =" 20 "value =" <? = $ _ V [2]?> "/>
</Label> </td>
<Td class = "align_c">
<A href = "javascript: sava ('c _ <? = $ _ V [3]?> ','S _ <? = $ _ V [3]?> ', <? = $ _ V [3]?> ); "> Save </a> |
<A href = "javascript: del ('<? = $ _ V [3]?> '); "> Delete </a> </td>
</Tr>
  
<? Php
   }
  }
?>
</Form>
</Table>
<Div style = "text-align: center; margin: 10px;"> <a href = "citymange. php"> Back to previous page </a> </div>

<Script language = "javascript">
Function del (id)
 {
If (confirm ('are you sure you want to delete this message? '))
  {
Location. href = 'public. php? Action = deletes & id = '+ id +' & aid = <? = $ Id?> & Cname = <? = PostGet ('cname');?> ';
  }
 
 }
 
Function sava (title, order, id)
 {
If (confirm ('Are you sure you have entered the correct data? '))
  {
Var cntitle = document. getElementById (title). value;
Var orderid = document. getElementById (order). value;
If ("" = cntitle | cntitle. length> 30)
   {
Alert ('region name cannot be blank! ');
   }
Else if (isNaN (orderid ))
   {
Alert ("Please enter a number for the sorting position! ");
   }
Else
   {
Location. href = "public. php? Action = edits & title = "+ cntitle +" & orderid = "+ orderid +" & id = "+ id +" & aid = <? = $ Id?> & Cname = <? = PostGet ('cname');?> ";
   }   
  } 
 }
</Script>
</Body>
</Html>


Public. php
Function deletes ()
 {
$ Id = PostGet ('id ');
$ Aid = PostGet ('aid ');
$ Cn = urlencode (PostGet ('cname '));
If (! Is_numeric ($ id ))
  {
Exit;
  }
Else
  {
$ Db = new Db ();
Try {
$ Db-> query ("Delete from cn_loupan_city where id = '$ ID '");
MessAge ('Operation successfully', 'type. php? Aid = '. $ aid.' & cname = '. $ cn );
} Catch (Execption $ e ){
MessAge ('Operation failed! ');
   }
$ Db-> close ();
  }
 }

Original site reprinted with www.111cn.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.