日期:2014-05-17 浏览次数:20704 次
<?php $id = $_GET['id']+0; if($id==0) { echo "参数有误"; exit; } $conn = mysql_connect('loaclhost','root','123456'); $sql = 'use msg'; mysql_query($sql,$conn); $sql = "select * from denglu where id = $id"; $var = mysql_query($sql,$conn); $msg = mysql_fetch_assoc($var); if(!$msg) { echo '参数有误'; exit; } print_r($msg); ?>
Notice: Undefined index: id in D:\server\apache\www\test.php on line 2 参数有误
http://localhost/test.php[color=#FF0000]?id=2[/color]
Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 in D:\server\apache\www\test.php on line 7 Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 (trying to connect via tcp://loaclhost:3306) in D:\server\apache\www\test.php on line 7 Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 in D:\server\apache\www\test.php on line 7 Warning: mysql_query() expects parameter 2 to be resource, boolean given in D:\server\apache\www\test.php on line 9 Warning: mysql_query() expects parameter 2 to be resource, boolean given in D:\server\apache\www\test.php on line 11 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in D:\server\apache\www\test.php on line 12 鍙傛暟鏈夎
$conn = mysql_connect('loaclhost','root','123456') or die("can not connect Mysql Server"); mysql_select_db("数据库名",$conn);//你的数据库名叫 use msg ? $sql = "select * from denglu where id = $id"; $var = mysql_query($sql);
------解决方案--------------------
<?php
if(isset($_REQUEST['id'])){
$id = $_REQUEST['id'];
if($id == 0){
exit("The parameter is wrong!");
}
}
echo $id;
@ $conn = mysql_connect('localost', 'root', '123456') or die("Connection Failure:" .mysql_errno());
mysql_select_db('msg', $conn);
mysql_query("set names ''utf8");
$sql = "select * from denglu where id = $id";
$result = mysql_query($sql);
while($rs = mysql_fetch_assoc($result)){
var_dump($rs);
}
输入url: localhost/index.php?id=2即可获取到id
------解决方案--------------------
$id=isset($_GET["id"])?$_GET["id"]:0;