any other way to do this? about accessing vars in $_POST...

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!

Moderator: General Moderators

Post Reply
mickey
Forum Newbie
Posts: 24
Joined: Thu May 01, 2003 11:14 am
Location: Philippines

any other way to do this? about accessing vars in $_POST...

Post 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,.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Use variable variavle names

Code: Select all

for ($i=0;$i<50;$i++)
&#123;
   $doc_var = "document_no_$i";
   $issue_var = "issue_date_$i";
   $expire_var = "expire_data_$i";
   if ($_POST&#1111;$doc_var]!='' && .... )
   &#123;
       // add to database
   &#125;
&#125;
mickey
Forum Newbie
Posts: 24
Joined: Thu May 01, 2003 11:14 am
Location: Philippines

Post by mickey »

nielsene wrote:Use variable variavle names

Code: Select all

for ($i=0;$i<50;$i++)
&#123;
   $doc_var = "document_no_$i";
   $issue_var = "issue_date_$i";
   $expire_var = "expire_data_$i";
   if ($_POST&#1111;$doc_var]!='' && .... )
   &#123;
       // add to database
   &#125;
&#125;
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...
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

mickey wrote:
nielsene wrote:Use variable variavle names

Code: Select all

for ($i=0;$i&lt;50;$i++)
&#123;
   $doc_var = "document_no_$i";
   $issue_var = "issue_date_$i";
   $expire_var = "expire_data_$i";
   if ($_POST&#1111;$doc_var]!='' &amp;&amp; .... )
   &#123;
       // add to database
   &#125;
&#125;
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');");
derek
Forum Newbie
Posts: 17
Joined: Sat Aug 16, 2003 11:31 am

Post 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'); ");
Post Reply