Home > Backend Development > PHP Tutorial > PHP利用Ajax联接到数据库

PHP利用Ajax联接到数据库

WBOY
Release: 2016-06-13 10:32:40
Original
859 people have browsed it

PHP利用Ajax连接到数据库
直接亮出来代码好了 这个是一个添加文章类别功能的页面
sortadd.php

<script><br />function checksort(){<br /> var txt_sort=form1.txt_sort.value;<br /> if(txt_sort==""){<br /> window.alert("请填写文章类别!");<br /> form1.txt_sort.focus();<br /> return false;<br /> }else{<br /> createRequest('checksort.php?txt_sort='+txt_sort);<br /> }<br />}<br /></script>



 
 
 
 
 
 
 
 

 

 
 

 

 






然后是checksort.php
/*
添加分类信息处理页checksort.php
 */
  $link=mysql_connect("localhost","root","8346322");
  mysql_select_db("wp",$link);
  $GB2312string=iconv('UTF-8','gb2312//IGNORE',$RequestAjaxString);
  mysql_query("set names gb2312");
  $sort=$_GET[txt_sort];
  mysql_query("insert into wp_jargon(jargon_text) values('$sort')");
  // header('Content-type:text/html;charset=GB2312');
?>


运行结果是:
如果添加的框是空的,还可以正常跳出提示对话框;但是如果不为空的时候就出错,几乎没什么相应。求求高手来解决下
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template