PHP 查询脚本

POST查询以表格传参数支持中文,GET不支持。

POST查询:

<?php
	$id=$_POST["id"];//id(中括号)为传来的参数,$id为php中的变量
	
	//localhost表示mysql的连接地址,这里表示本地,后面为mysql的账号密码
	$con=mysql_connect("localhost","root","root");
	
	if(!$con)
	{
		die('Could not connect:'.mysql_error());
	}
	
	//“jxxy”为自己在mysql中创建的数据库名称
	mysql_select_db("jxxy",$con);
	
	//结果
	//第一个括号为SQL语句,''表示字符串,.表示连接符
	$result = mysql_query("select jkxx FROM 't_kaohe' where id = '".$id."' ") or die('false');
	
	//处理结果,一条用if,多条用while
	if($row= mysql_fetch_array($result))
	{
		//echo 表示输出
		echo $row['jkxx'];
	}
	mysql_close($con);
?>

GET查询:

<?php
	$id=$_GET["id"];
	
	$con=mysql_connect("localhost","root","root");
	
	if(!$con)
	{
		die('Could not connect:'.mysql_error());
	}
	
	mysql_select_db("jxxy",$con);
	
	$result = mysql_query("select jkxx FROM 't_kaohe' where id = '".$id."' ") or die('false');
	
	if($row= mysql_fetch_array($result))
	{
		echo $row['jkxx'];
	}
	mysql_close($con);
?>
	

插入,删除,更新之类的操作,与查询操作同理,只是SQL语句不一样而已。


原文地址:https://www.cnblogs.com/liang123/p/6325922.html