| | |
Msql. Insert data depending on which form field is filled out.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2008
Posts: 20
Reputation:
Solved Threads: 0
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
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')");•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 2
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.
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
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
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
•
•
Join Date: Jan 2009
Posts: 34
Reputation:
Solved Threads: 3
Like what I think is stated above, you probably want to go by upload first meaning
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.
PHP Syntax (Toggle Plain Text)
//Before should be all other variables like $site,$containingfolder, etc if(isset($_FILES['uploadedfile']['tmp_name'])){ $url = $site.$containingfolder.$_FILES['uploadedfile']['tmp_name']; }elseif(isset($_POST['url'])){ $url = $_POST['url']; }else{ die(); } //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.
![]() |
Other Threads in the PHP Forum
- Previous Thread: mssql_query() problem calling SQL Server Project (SP)
- Next Thread: PHP MySQL date question.
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner beneath binary broadband broken button cakephp checkbox class cms code compression countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html httppost image include insert integration ip javascript joomla limit link links login mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion remote script search searchbox server session sessions sms smtp source space sql strip_tags survey syntax system table tutorial update upload url validator variable video virus votedown web website window.onbeforeunload=closeme; youtube






