PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i am new to php and am really struggling with something that to me seems like it should be quite simple...
is it possible to submit empty form fields to a mysql db using php?
i have built a simple new cms system which works fine if users complete all the forms, but if a user leaves a field blank the php script fails to run and nothing gets sumitted to the db.
i can get round the majority of this problem by using javascript, but my real problem is that i have a file upload field that i can't use javascript on to add a hidden value if a user does not add anything. ideally i would like to submit nothing if the user does not wantto submit anything.
can anyone give me any advice? i can't believe it can be as difficult as i am finding it...
well, this could be due to a few things, namely how you are checking the data before you send it to mysql.
anyway we can see some of the code? especially your query. if it's quite long, only post the portions that control the data that isn't getting put into the db.
depend on your table structure... I mean if you are trying to insert blank value to a field that is set as "NOT NULL" then you are ought to get an error. make sure that field can be NULL fo even if form is submitted with blank values it shouldn't throw errors...
secondly if you are using some checking while running SQL query...
well.. to say anything more... we should see smoe code.. like infolock said.. :
it doesn't throw back any error, the script just fails.
if all fields are completed the script runs fine.
if i leave one of the upload fields blank it fails - so i'm assuming it is a problem with empty fields.
i would have thought it possible to submit empty values. is this not the case.
apologies for not tagging my code - i'll go back and change them if i can.
this is the sql that adds the form data to the db, it works fien when all firelds contain a value, but if image, file1 or file2 are empty then it fails.
check my second post in this thread, it gets called there.
sorry if i'm not making much sense, but php is not my forte, this code is stuff i have managed to cobble together from searching the web and other peoples tutorials.