Page 1 of 1

Checking to see if variable has value

Posted: Tue Jan 28, 2003 6:29 pm
by nigma
I have a form that you use to add rows to my database, sometimes I have to add multiple rows, so I made more input fields so I can add more than one row without having to go back to the page. But I dont always want to use these. So is there a way I can check(before adding the row) to see if the field has a value? Someone give example?

Thanks.

Posted: Tue Jan 28, 2003 8:57 pm
by hedge
My way is not foolproof but has worked quite well so far. I create an md5 hidden input for each db row based on the data I sent to the page. When they post it back I re-calc the md5. If it is different then they must have 'touched' that row. This method also allows me to avoid updating rows that have not changed.

Posted: Tue Jan 28, 2003 10:44 pm
by Stoker
I don't think Kris was looking for data checksum/signature/security, rather to see if a field/value was set..

It's as simple as using empty() which returns true if the variable is not assigned, contains an empty string or the value 0..

if (!empty($_POST['somevar'])) {
# do the query
}

Posted: Wed Jan 29, 2003 7:19 am
by DaZZleD
also you can always use isset($variable) which returns true if the variable was set or false otherwise.