Hi guys, I was trying to figure out this problem for whole day without getting anywhere. I'm quite inexperienced in php but I'm doing my best.
I have this LAMP thingie running on my server, it's a simple php driven website where i can do queries against my mysql database and also add new stuff.
For that i designed a form. This is a recording-database, and one among the fields that I fill in is a "Date" field (not a date datatype in mysql, put simply a varchar to make it more simple). What I need to do in php is to make a conditional statement so that, if I leave this field untouched (empty) and hit 'Submit' with other fields filled in properly - the date form should automatically get the value 'unknown' and the query should be done successfully with this Date=unknown value. I tried to make it work something like this (i'm only including relevant fields in the code so you get a picture what I'm talking about):
PHP Code:
$date=$_REQUEST['date'];
if(!empty($date) {
$date = "unknown"
}
$dbadd = "INSERT INTO recordings values (NULL,'$date', '$artist','$venue','$city','$countrystate','$media','$storageid')";
So basically, what I was expecting this would do was, in case I didn't fill in the date - it would do the insert query to the database with all other stuff added (according to what I filled in) + date = unknown. What it does, however, is that it does a successful addition to my mysql database but date remains empty. How do I successfully declare this variable? First I thought it was something wrong with conditional-statement itself, so I altered it in debugging purposes, writing something like:
PHP Code:
if(!empty($date) {
echo "No date added";
exit;
}
This time the program would stop without adding anything to database and print that error-message. So, the program seems to be reacting to the conditional. So it's only when I try to set the value to the variable and actually make it go through mysql - that I get my problems.
I hope I made myself clear.
Thanks in advance!