php接收地址栏上的id,该怎么解决

WBOY
Lepaskan: 2016-06-13 10:11:41
asal
1283 orang telah melayarinya

php接收地址栏上的id

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?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);?>
Salin selepas log masuk

文件命名为test.php,编辑环境为editplus,按ctrl+b,在页面上弹出
HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Notice: Undefined index: id in D:\server\apache\www\test.php on line 2参数有误
Salin selepas log masuk

于是我便在地址栏上输入
HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->http://localhost/test.php[color=#FF0000]?id=2[/color]
Salin selepas log masuk

可是这次显示的错更多
HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 in D:\server\apache\www\test.php on line 7Warning: 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 7Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 in D:\server\apache\www\test.php on line 7Warning: mysql_query() expects parameter 2 to be resource, boolean given in D:\server\apache\www\test.php on line 9Warning: mysql_query() expects parameter 2 to be resource, boolean given in D:\server\apache\www\test.php on line 11Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in D:\server\apache\www\test.php on line 12鍙傛暟鏈夎
Salin selepas log masuk

我查找原因好久,实在没招了,哪位大大能帮忙分析原因,感激不尽!!!!!

------解决方案--------------------
mysql_connect(), 数据库连接错误

PHP code
$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);<br><font color="#e78608">------解决方案--------------------</font><br><?php <br />if(isset($_REQUEST['id'])){<br>	$id = $_REQUEST['id'];<br>	if($id == 0){<br>		exit("The parameter is wrong!");<br>	}<br>}<br>echo $id;<br>@ $conn = mysql_connect('localost', 'root', '123456') or die("Connection Failure:" .mysql_errno());<br>mysql_select_db('msg', $conn);<br>mysql_query("set names ''utf8");<br>$sql =  "select * from denglu where id = $id";<br>$result = mysql_query($sql);<br>while($rs = mysql_fetch_assoc($result)){<br>   var_dump($rs);<br>}<br>输入url: localhost/index.php?id=2即可获取到id<br><font color="#e78608">------解决方案--------------------</font><br>$id=isset($_GET["id"])?$_GET["id"]:0;<div class="clear">
                 
              
              
        
            </div>
Salin selepas log masuk
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan