hi, my page contains this inputs with names like
document_no_1 till document_no_50
issued_date_1 till issued_date_50
expiry_date_1 till expiry_date_1
and so on...,
before i place them in a database, i need to see first if those filled are filled up by the user, ie,
if($_POST['document_no_1'] !- NULL || $_POST['issued_date_1'] !- NULL) and so with the other vars and so on...
that means a long list of if else checking each and every var names.. any other way to di it faster? perhaps a for statement? but how?
many thanks,.
any other way to do this? about accessing vars in $_POST...
Moderator: General Moderators
Use variable variavle names
Code: Select all
for ($i=0;$i<50;$i++)
{
$doc_var = "document_no_$i";
$issue_var = "issue_date_$i";
$expire_var = "expire_data_$i";
if ($_POSTї$doc_var]!='' && .... )
{
// add to database
}
}hello nielsene,nielsene wrote:Use variable variavle namesCode: Select all
for ($i=0;$i<50;$i++) { $doc_var = "document_no_$i"; $issue_var = "issue_date_$i"; $expire_var = "expire_data_$i"; if ($_POSTї$doc_var]!='' && .... ) { // add to database } }
i've already tried that, you see, i don't think that would work...
when i will try to do this,
mysql_query("INSERT INTO documentNo, issuedDate VALUES($doc_var, $issue_var)")...
the contents would be the strings not the actual value...
You need to use double dollar-signs there... e.g.mickey wrote:hello nielsene,nielsene wrote:Use variable variavle namesCode: Select all
for ($i=0;$i<50;$i++) { $doc_var = "document_no_$i"; $issue_var = "issue_date_$i"; $expire_var = "expire_data_$i"; if ($_POSTї$doc_var]!='' && .... ) { // add to database } }
i've already tried that, you see, i don't think that would work...
when i will try to do this,
mysql_query("INSERT INTO documentNo, issuedDate VALUES($doc_var, $issue_var)")...
the contents would be the strings not the actual value...
Code: Select all
mysql_query("INSERT INTO foo (`documentNo`,`issuedDate`) VALUES ('$$doc_var','$$issue_var');");Yes, you have to use Double Dollar ($$) while entering the data in the database.
Code: Select all
mysql_query("insert into table_name (`documentNo`,`issuedDate`) values ('$$doc_var', '$$issue_var'); ");