<?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'];不能获取路径啊。其他的都行。

解决方案 »

  1.   

    1.你的上传页面贴出来2.把你的$_$_POST打出来看看看
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <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">&nbsp;</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">&nbsp;</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>
      

  3.   

    首先 你能正确提交你的数据吗  先别向数据库里面录入 先把你要传递的参数遍历输出
    print_r($_POST);
    看是否数据完整 
    然后把SQL语句 输出 就是 你最后提交数据后的生成要插入的语句
    然后把这个语句 直接在Mysql中运行(phpmyadmin,命令行)都行
    通过这些排错 你基本上就可以明白自己哪里出错了! 
      

  4.   

    print_r($_POST);
    PRINT_R($_FILES);
      

  5.   

    是不是要截取路径啊?我直接用SQL语句能添加进去,$Url =$_POST['Url'];就不行
      

  6.   

    Array ( [musicName] => sss [singerName] => sss [area] => sss [style] => sss [other] => sssss [upload] => upload ) 
    Array ( [newSong] => Array ( [name] => 如果这就是爱情.mp3 [type] => audio/mp3 [tmp_name] => C:\WINDOWS\temp\php31E.tmp [error] => 0 [size] => 4530721 ) ) 数据添加成功.  何解?
      

  7.   

    Array ( [newSong] => Array ( [name] => 如果这就是爱情.mp3 [type] => audio/mp3 [tmp_name] => C:\WINDOWS\temp\php31E.tmp [error] => 0 [size] => 4530721 ) )我只想获取这个[name] => 如果这就是爱情.mp3 。有什么办法?
      

  8.   

    $_FILES['newSong']['name']
    这个就是获得:如果这就是爱情.mp3 
      

  9.   

    你应该把你的代码贴出来的  正常的是可以插入的  比如 $url = "http://www.00562.com/index.php";  $sql = "insert into biao values (null,'".$url."')";这样是可以插入数据的 
    -----------------------------------
    http://www.jiemengwu.com/ 解梦屋 http://www.phpzy.com/php/ 绿色php资源
      

  10.   

    OK啦!谢谢大家!$_FILES['newSong']['name']
     获取文件名后 $exec = "INSERT INTO musiclist(musicName,singerName,area,Url,other,style) VALUES ('$musicName','$singerName','$area','E:/AppServ/www/lyko2/music1/$Url','$other','$style')"; 直接往SQL语句里加
      

  11.   

    var_dump($_POST['Url']); 看看什么情况 可能是空值   没有获取到 获取上传文件信息  有$_FILES、、、具体情况  一步一步 排查吧、、、