PHP问题!为什么$_GET里面的参数未定义?
edituser.php<!DOCTYPEhtml><html><head><title>编辑用户</title></head><body><?phprequire_on...
edituser.php
<!DOCTYPE html>
<html>
<head>
<title>编辑用户</title>
</head>
<body>
<?php
require_once 'functions.php';
if(!empty($_GET['id'])){
connectDb();
$id = intval($_GET['id']);
$result = mysql_query("select * from users where id = $id ");
if(mysql_error()){
die("cannot connect db");
}
$arr = mysql_fetch_assoc($result);
print_r($arr);
}
else{
die('id not define');
}
?>
</body>
</html>
allUsers.php
<?php
require_once 'functions.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
<title>所有用户</title>
</head>
<body>
<a href="adduser.html">添加用户</a>
<table width='100%' border='1' solid='1' > <tr><th>id</th><th>name</th><th>age</th><th>update</th></tr>
<?php
$conn = connectDb();
$result = mysql_query("SELECT * FROM USERS");
$dataCount = mysql_num_rows($result);
while($dataCount--){
$result_arr = mysql_fetch_assoc($result);
// print_r($result_arr);
$id = $result_arr['id'];
$name = $result_arr['name'];
$age = $result_arr['age'];
echo "<tr>
<td>$id</td>
<td>$name</td>
<td>$age</td>
<td><a href='edituser.php?id = $id'>update</a></td>
</tr>";
// <?php
}
?>
</table>
</body>
</html>
functions.php
<?php
require_once 'config.php';
function connectDb(){
$conn = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PW);
if(!$conn){
die('cannot connected');
}
mysql_select_db('myapp',$conn);
return $conn;
}
执行allUsers页面的update时显示get里面的id没有定义,怎么解决?
config.php
<?php
define ('MYSQL_HOST','localhost');
define ('MYSQL_USER','root');
define ('MYSQL_PW',''); 展开
<!DOCTYPE html>
<html>
<head>
<title>编辑用户</title>
</head>
<body>
<?php
require_once 'functions.php';
if(!empty($_GET['id'])){
connectDb();
$id = intval($_GET['id']);
$result = mysql_query("select * from users where id = $id ");
if(mysql_error()){
die("cannot connect db");
}
$arr = mysql_fetch_assoc($result);
print_r($arr);
}
else{
die('id not define');
}
?>
</body>
</html>
allUsers.php
<?php
require_once 'functions.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
<title>所有用户</title>
</head>
<body>
<a href="adduser.html">添加用户</a>
<table width='100%' border='1' solid='1' > <tr><th>id</th><th>name</th><th>age</th><th>update</th></tr>
<?php
$conn = connectDb();
$result = mysql_query("SELECT * FROM USERS");
$dataCount = mysql_num_rows($result);
while($dataCount--){
$result_arr = mysql_fetch_assoc($result);
// print_r($result_arr);
$id = $result_arr['id'];
$name = $result_arr['name'];
$age = $result_arr['age'];
echo "<tr>
<td>$id</td>
<td>$name</td>
<td>$age</td>
<td><a href='edituser.php?id = $id'>update</a></td>
</tr>";
// <?php
}
?>
</table>
</body>
</html>
functions.php
<?php
require_once 'config.php';
function connectDb(){
$conn = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PW);
if(!$conn){
die('cannot connected');
}
mysql_select_db('myapp',$conn);
return $conn;
}
执行allUsers页面的update时显示get里面的id没有定义,怎么解决?
config.php
<?php
define ('MYSQL_HOST','localhost');
define ('MYSQL_USER','root');
define ('MYSQL_PW',''); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询