<?php
$conn=mysql_connect('localhost','root','root') or die('连接失败!'.mysql_error());
mysql_select_db('music',$conn) or die('数据库选择失败:' . mysql_error());
mysql_query("set names gb2312");
$musicName =$_POST['musicName'];
$singerName =$_POST['singerName'];
$area =$_POST['area'];
$Url =$_POST['Url'];
$other =$_POST['other'];
$style =$_POST['style'];
$exec = "INSERT INTO musiclist(musicName,singerName,area,Url,other,style) VALUES ('$musicName','$singerName','$area','$Url','$other','$style')";
$quer = mysql_query($exec);
if ($quer){
die('数据添加成功.');
}else{
die('数据添加失败.');
}
mysql_close($conn);
?>还有个上传页面:<input type="file" name="newSong" title="select Song" lang="en" />,这个是上传控件。能直接传到数据库,但$Url =$_POST['Url'];不能获取路径啊。其他的都行。
$conn=mysql_connect('localhost','root','root') or die('连接失败!'.mysql_error());
mysql_select_db('music',$conn) or die('数据库选择失败:' . mysql_error());
mysql_query("set names gb2312");
$musicName =$_POST['musicName'];
$singerName =$_POST['singerName'];
$area =$_POST['area'];
$Url =$_POST['Url'];
$other =$_POST['other'];
$style =$_POST['style'];
$exec = "INSERT INTO musiclist(musicName,singerName,area,Url,other,style) VALUES ('$musicName','$singerName','$area','$Url','$other','$style')";
$quer = mysql_query($exec);
if ($quer){
die('数据添加成功.');
}else{
die('数据添加失败.');
}
mysql_close($conn);
?>还有个上传页面:<input type="file" name="newSong" title="select Song" lang="en" />,这个是上传控件。能直接传到数据库,但$Url =$_POST['Url'];不能获取路径啊。其他的都行。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body >
<script type="text/javascript"></script>
<form enctype="multipart/form-data" action="videoProcess.php" lang="en" method="post" name="upload" >
<h3> 上传</h3>
<p style="width:400px;"align="center"> </p>
<p style="width:400px;"align="center">歌曲名:
<input type="text" name="musicName" /></p>
<p style="width:400px;"align="center">所属歌手:
<input type="text" name="singerName">
</p>
<p style="width:400px;"align="center">所属地区:
<input type="text" name="area" />
</p>
<p style="width:400px;"align="center">所属风格:
<input type="text" name="style" />
</p>
<p style="width:400px;"align="center">备注:
<input type="text" name="other" />
</p>
<p style="width:400px;"align="center"> </p>
<p style="width:400px;"align="center">
<input type="file" name="newSong" title="select Song" lang="en" />
</p>
<p style="width:400px;"align="center">
<input type="submit" name="upload" value="upload" />
</p>
</form>
</body>
</html>
print_r($_POST);
看是否数据完整
然后把SQL语句 输出 就是 你最后提交数据后的生成要插入的语句
然后把这个语句 直接在Mysql中运行(phpmyadmin,命令行)都行
通过这些排错 你基本上就可以明白自己哪里出错了!
PRINT_R($_FILES);
Array ( [newSong] => Array ( [name] => 如果这就是爱情.mp3 [type] => audio/mp3 [tmp_name] => C:\WINDOWS\temp\php31E.tmp [error] => 0 [size] => 4530721 ) ) 数据添加成功. 何解?
这个就是获得:如果这就是爱情.mp3
-----------------------------------
http://www.jiemengwu.com/ 解梦屋 http://www.phpzy.com/php/ 绿色php资源
获取文件名后 $exec = "INSERT INTO musiclist(musicName,singerName,area,Url,other,style) VALUES ('$musicName','$singerName','$area','E:/AppServ/www/lyko2/music1/$Url','$other','$style')"; 直接往SQL语句里加