Page 1 of 1
any other way to do this? about accessing vars in $_POST...
Posted: Sun Aug 17, 2003 12:14 pm
by mickey
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,.
Posted: Sun Aug 17, 2003 12:23 pm
by nigma
Do you only want to check to see if a user has entered input or do you want to check to see if user has entered input but has also entered valid input? If so what is your criteria for valid input?
Posted: Sun Aug 17, 2003 5:54 pm
by nielsene
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
}
}
Posted: Sun Aug 17, 2003 8:34 pm
by mickey
nielsene wrote: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,
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...
Posted: Sun Aug 17, 2003 9:40 pm
by nielsene
mickey wrote:nielsene wrote: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,
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.
Code: Select all
mysql_query("INSERT INTO foo (`documentNo`,`issuedDate`) VALUES ('$$doc_var','$$issue_var');");
Posted: Mon Aug 18, 2003 2:39 am
by derek
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'); ");