Just hoping someone could point out how to do this: Users can either insert a link to audio or upload audio. Rather than have 2 separate fields in my mysql table (that would lead to more probs) I want to insert depending on which form field has been entered.

ie if I upload the audio, then php inserts the file extension or if I link the audio, php does the same.

I know below is wrong but you can see what I mean. Would a conditional statement do the trick?


mysql_query("INSERT INTO $table (show_id, date, dj, author, description, file, file, visible) VALUES ('$show', '$date', '$dj', '$author',  '$description', '$file', '$query', '$visible')");
9 Years
Discussion Span
Last Post by jrdark13

You could use the isset() function of php. You have to check which post variable is set like isset($_POST[var]). This returns 1 if the values is set else it returns a 0.
Before inserting it in the db u could check which option the user has chosen.


examine the data
validate it to your requirements
if a file or url check whether it exists
if a file upload to temporary space on the server
if a file check whether it is an appropriate file type, not just an appropriate filename
if a url ensure that it is a media file, on a server that permits off site linking
then create a query and validate the query
then update the database
anything else is asking for attack


Like what I think is stated above, you probably want to go by upload first meaning

//Before should be all other variables like $site,$containingfolder, etc

 $url = $site.$containingfolder.$_FILES['uploadedfile']['tmp_name'];
 $url = $_POST['url'];

//Code continues to insert to DB

check out this tutorial as to what variables to us to verify file was uploaded and MAKE SURE YOU PUT "USER INPUT ERROR"/"HACKING" CHECKS. The example above was a really rough sketch and untested (Not for production).

Also some javascript to disable fields by the use of radios would be very helpful on the user side but not much for protection.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.