Jump to content

Recommended Posts

I made a application where you can store hardware information etc. But i want different types of properties for every kind of hardware. So a laptop has the properties:

 

memory

Processor

etc.

 

and a mobile phone knows other property's like:

 

Camera yes/no

etc.

 

I have to fill in this properties into a variable number of textfields. This information must be stored in a database. But because i have a variable number of textfields the names of the textfields are always different. Into the next page i have to open this information with a post, but how do i call this textfields? Can i place a variable into a $_POST? Like this $_POST[$name]?

Link to comment
https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/
Share on other sites

Can i place a variable into a $_POST? Like this $_POST[$name]?

 

Of course, but you'll likely not need to. Just name your text fields as array elements. eg;

 

<input type="text" name="property[]">
<input type="text" name="property[]">
<input type="text" name="property[]">

 

Then, on the recieving page they will be in the array $_POST['property']. You can then loop through this array.

Oke, i've tried something but it does not work, so i have create 2 testfiles with the following code:

 

test.php

<?

$naam = "txttest";

?>

 

<form id="form1" name="form1" method="post" action="uitkomst.php">

  <label>

  <input type="text" name= "<? $naam ?>" />

  </label>

  <label>

  <input type="submit" name="Submit" value="Submit" />

  </label>

</form>

 

and uitkomst.php

 

<?

$naam = "txttest";

 

echo $_POST[$naam];

 

?>

 

This is only a testfile but the weppage does not echo anything, so something is wrong but what? ???

This line...

 

<input type="text" name= "<? $naam ?>" />

 

should be....

 

<input type="text" name="<? $naam ?>" />

 

to make it valid html. Otherwise, I don't see a problem.

 

I think however youv'e missed the point of my last few replies. Firstly, short tags shouldn't be used, there not portable. And secondly, if your creating a variable amount of text inputs your better off naming them using arrays in the first place.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.