spires Posted July 17, 2006 Share Posted July 17, 2006 Hi, I posted earlyer and a few of you really pointed me in the right direction. But as usual, i'm stuck.I have uploaded the mp3s to the server, and the id and date have been placed inside the database. But, i cant seem to get the 'name' and 'userfile_name' to load into the database. Can someone have a quick look at my code and point me in the right direction. ;DThanks[code]<?phpinclude('db.php'); echo ' <center> <table cellpadding="0" cellspacing="0" width="400" class="TLRB_border"> <tr> <td align="center"> <strong>"All audio must be .mpeg files"</strong><br><br> <form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="'.$_POST['320834100'].'"> <input type="hidden" name="id" value="'.$_POST['id'].'"> <input type="hidden" name="date_sent" value="'.$_POST['date_sent'].'"> <br>please choose a music file<br> <input type="file" name="userfile"><p> <input type="Submit" name="Submit" value="Submit"> </form> </td> </tr> </table><br> </center>';$query="select * from music where name='$name' and id='$id'";$result=mysql_query($query);while($row=mysql_fetch_assoc($result)) {if($row["userfile_name"]=1) { echo "<b>Sorry you have a video already</b><br><br><a href='../index.php'>Update music</a><br><br>"; exit; }} if(!isset($_FILES['userfile'])=="none") { echo"no file specified<br><a href='upload.php'>please try again1</a><br><br>"; exit; } $uploaddir ="mp3/"; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $size=$_FILES['userfile']['size']; $type=($_FILES['userfile']['type']=="audio/mpeg"); if($size <= 320834100) { if($type) { if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)) { $date_sent = date("Y-m-d"); $id = $_POST['id']; $userfile_name = $_POST['userfile_name']; $name = $_POST['name']; $userfile_name = addslashes($userfile_name); $query="INSERT INTO music (id, name, date_sent, userfile_name) VALUES ('$id', '$name', '$date_sent', '$userfile_name')"; $result=mysql_query($query); echo "file uploaded"; }else{ echo"no file uploaded <br><br><br><a href='upload.php'>please try again2</a><br><br>"; exit; } }else{ echo"sorry wrong file type .mp3 only<br><br><br><a href='upload.php'>please try again3</a><br><br>"; exit; } }else{ echo"sorry wrong file type .mp3 only<br><br><br><a href='upload.php'>please try again4</a><br><br>"; exit; }?><?php$music_query="SELECT * FROM music WHERE id='$id'";$music_result=mysql_query($music_query);while($mus=mysql_fetch_assoc($music_result)) {$music_link="<embed src='mp3/".$mus["userfile_name"]."' bgcolor='#A0C0F0' width='125' height='125' autostart='false' loop='false' >";}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 Your form has no element named 'name' so this... $name = $_POST['name']; is redundant.ps: What editor are you using? Those tabs are anoyingly difficult to read. Quote Link to comment Share on other sites More sharing options...
pixy Posted July 17, 2006 Share Posted July 17, 2006 ^ Agreed about the tabs--they're slightly ridiculous to look at. It seems a lot of people have been posting code that's just all over the map and completely unorginized. O_O Quote Link to comment Share on other sites More sharing options...
spires Posted July 17, 2006 Author Share Posted July 17, 2006 OK, ThanksExplain please. i'm very new to PHP. Quick questionHow does the $_FILES read the name of the mp3?How does it know what its callled and what part of the code does this?I've only just started learning how to do this, and am not to shore how it all works yet. Quote Link to comment Share on other sites More sharing options...
spires Posted July 17, 2006 Author Share Posted July 17, 2006 any better?[code]<link href="../css/nicky.css" rel="stylesheet" type="text/css"><?phpinclude('db.php'); echo ' <center> <table cellpadding="0" cellspacing="0" width="400" class="TLRB_border"> <tr> <td align="center"> <strong>"All audio must be .mpeg files"</strong><br><br> <form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="'.$_POST['320834100'].'"> <input type="hidden" name="name" value="'.$_POST['name'].'"> <input type="hidden" name="userfile_name" value="'.$_POST['userfile_name'].'"> <input type="hidden" name="id" value="'.$_POST['id'].'"> <input type="hidden" name="date_sent" value="'.$_POST['date_sent'].'"> <br>please choose a music file<br> <input type="file" name="userfile"><p> <input type="Submit" name="Submit" value="Submit"> </form> </td> </tr> </table><br> </center>';$query="select * from music where name='$name' and id='$id'";$result=mysql_query($query);while($row=mysql_fetch_assoc($result)) {if($row["userfile_name"]=1) { echo "<b>Sorry you have a video already</b><br><br><a href='../index.php'>Update music</a><br><br>"; exit; }} if(!isset($_FILES['userfile'])=="none") {echo"no file specified<br><a href='upload.php'>please try again1</a><br><br>";exit;} $uploaddir ="mp3/";$uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $size=$_FILES['userfile']['size'];$type=($_FILES['userfile']['type']=="audio/mpeg"); if($size <= 320834100) { if($type) { if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)) { $date_sent = date("Y-m-d");$id = $_POST['id'];$userfile_name = $_POST['userfile_name'];$name = $_POST['name']; $userfile_name = addslashes($userfile_name); $query="INSERT INTO music (id, name, date_sent, userfile_name) VALUES ('$id', '$name', '$date_sent', '$userfile_name')"; $result=mysql_query($query); echo "file uploaded"; }else{echo"no file uploaded <br><br><br><a href='upload.php'>please try again2</a><br><br>";exit;} }else{echo"sorry wrong file type .mp3 only<br><br><br><a href='upload.php'>please try again3</a><br><br>";exit;} }else{echo"sorry wrong file type .mp3 only<br><br><br><a href='upload.php'>please try again4</a><br><br>";exit;}?><?php$music_query="SELECT * FROM music WHERE id='$id'";$music_result=mysql_query($music_query);while($mus=mysql_fetch_assoc($music_result)) {$music_link="<embed src='mp3/".$mus["userfile_name"]."' bgcolor='#A0C0F0' width='125' height='125' autostart='false' loop='false' >";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.