<?php
require_once("connect_mysql.php"); //引用数据库连接文件
$uname = $_GET['username']; //用GET方法为URL参数传递
$pwd = $_GET['pwd'];
$reason = $_GET['reason'];
$pwd = md5($pwd); //直接用MD5加密
$sql = "insert into user(username,pwd,reason) vlaues('$uname','$pwd','reason')";
mysql_query($sql);
mysql_close();
echo "成功录入数据库";
?>
connect_mysql.php页面
<?php
$link = mysqli_connect( /* Connect to a MySQL server 连接数据库服务器 */
'localhost', /* The host to connect to 连接MySQL地址 */
'root', /* The user to connect as 连接MySQL用户名 */
'', /* The password to use 连接MySQL密码 */
'0135'); /* The default database to query 连接数据库名称*/
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error()); exit; } /* Send a query to the server 向服务器发送查询请求*/
if ($result = mysqli_query($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {
print("Very large cities are: "); /* Fetch the results of the query 返回查询的结果 */
while( $row = mysqli_fetch_assoc($result) ){
printf("%s (%s) ", $row['Name'], $row['Population']); } /* Destroy the result set and free the memory used for it 结束查询释放内存 */
mysqli_free_result($result); } /* Close the connection 关闭连接*/
mysqli_close($link);
?>
一下是post.php页面出现的错误
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\APMServ-v5.2.6\APMServ5.2.6\www\htdocs\post.php on line 16
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in E:\APMServ-v5.2.6\APMServ5.2.6\www\htdocs\post.php on line 16
Warning: mysql_close(): no MySQL-Link resource supplied in E:\APMServ-v5.2.6\APMServ5.2.6\www\htdocs\post.php on line 17
成功录入数据库
这是怎么回事,是数据库没密码造成的吗??????望高人指点一二..........................................
4 个解决方案
#1
你在connect_mysql.php里已经把数据库资源释放掉了
后面接着用数据库 当然就没头没脑了
后面接着用数据库 当然就没头没脑了
#2
你可以判断一下是否写入成功,可以看到实际执行的insert语句,用getLastsql
#3
把connect_mysql.php里面的mysqli_close($link); 去掉试试。
#4
的确是个小问题,天大意了!!!
#1
你在connect_mysql.php里已经把数据库资源释放掉了
后面接着用数据库 当然就没头没脑了
后面接着用数据库 当然就没头没脑了
#2
你可以判断一下是否写入成功,可以看到实际执行的insert语句,用getLastsql
#3
把connect_mysql.php里面的mysqli_close($link); 去掉试试。
#4
的确是个小问题,天大意了!!!