php接收地址欄上的id,該怎麼解決

來源:互聯網
上載者:User
php接收地址欄上的id
PHP code


檔案命名為test.php,編輯環境為editplus,按ctrl+b,在頁面上彈出
HTML code
Notice: Undefined index: id in D:\server\apache\www\test.php on line 2參數有誤

於是我便在地址欄上輸入
HTML code
http://localhost/test.php[color=#FF0000]?id=2[/color]

可是這次顯示的錯更多
HTML code
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鍙傛暟鏈夎

我尋找原因好久,實在沒招了,哪位大大能幫忙分析原因,感激不盡!!!!!

------解決方案--------------------
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);
------解決方案--------------------
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;
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.