Msql. Insert data depending on which form field is filled out.

Reply

Join Date: Nov 2008
Posts: 20
Reputation: stevehart808 is an unknown quantity at this point 
Solved Threads: 0
stevehart808 stevehart808 is offline Offline
Newbie Poster

Msql. Insert data depending on which form field is filled out.

 
0
  #1
Jan 16th, 2009
Hi,

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?

Thanks

mysql_query("INSERT INTO $table (show_id, date, dj, author, description, file, file, visible) VALUES ('$show', '$date', '$dj', '$author',  '$description', '$file', '$query', '$visible')");
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 12
Reputation: scaraffe is an unknown quantity at this point 
Solved Threads: 2
scaraffe scaraffe is offline Offline
Newbie Poster

Re: Msql. Insert data depending on which form field is filled out.

 
0
  #2
Jan 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,318
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 161
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Msql. Insert data depending on which form field is filled out.

 
0
  #3
Jan 16th, 2009
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
Last edited by almostbob; Jan 16th, 2009 at 1:18 pm.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 34
Reputation: jrdark13 is an unknown quantity at this point 
Solved Threads: 3
jrdark13 jrdark13 is offline Offline
Light Poster

Re: Msql. Insert data depending on which form field is filled out.

 
0
  #4
Jan 16th, 2009
Like what I think is stated above, you probably want to go by upload first meaning
  1. //Before should be all other variables like $site,$containingfolder, etc
  2.  
  3. if(isset($_FILES['uploadedfile']['tmp_name'])){
  4. $url = $site.$containingfolder.$_FILES['uploadedfile']['tmp_name'];
  5. }elseif(isset($_POST['url'])){
  6. $url = $_POST['url'];
  7. }else{
  8. die();
  9. }
  10.  
  11. //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.
Last edited by jrdark13; Jan 16th, 2009 at 2:48 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC