PHP and Array problem
Moderator: General Moderators
PHP and Array problem
Hello,
I have my textfields in array and want to print the value. When i'm doing this i get no result =>
echo $_POST["project_verkoopprijs[0]"];
Can someone tells me what i'm doing wrong?
Best Regards,
Kris Saelen
I have my textfields in array and want to print the value. When i'm doing this i get no result =>
echo $_POST["project_verkoopprijs[0]"];
Can someone tells me what i'm doing wrong?
Best Regards,
Kris Saelen
That depends on the type of variable that project_verkoopprijs is.
Have a look at this sample code to see the difference
Hope this helps
Have a look at this sample code to see the difference
Code: Select all
// setup some test data
$_POST['variable'] = 'Some Variable';
$_POST['arr'] = array('Array One', 'Array Two');
// Print the complete contents of the POST array
echo ' print_r POST--'; print_r($_POST); echo '<br />';
// print the contest of the 'variable' element of the POST array
echo ' $_POST[variable]--' . $_POST['variable'] . '<br />';
// print the first element of the 'arr' array within the POST array
echo '$_POST[arr][0]--' . $_POST['arr'][0] . '<br />';I'm also having an error with this =>
<select name=project[<? echo $counter; ?>] onChange="document.forms['frm_facaanmaken'].elements['project_verkoopprijs[<?echo $counter; ?>]'].value = <? echo "$verkoopprijs[this.options[this.selectedIndex].value]"; ?>;" style="height:18;" height=24>
this is the error => echo "$verkoopprijs[this.options[this.selectedIndex].value]";
But i need this because when i change the select control and choose another item it needs to put the price of that item in the price_field.
<select name=project[<? echo $counter; ?>] onChange="document.forms['frm_facaanmaken'].elements['project_verkoopprijs[<?echo $counter; ?>]'].value = <? echo "$verkoopprijs[this.options[this.selectedIndex].value]"; ?>;" style="height:18;" height=24>
this is the error => echo "$verkoopprijs[this.options[this.selectedIndex].value]";
But i need this because when i change the select control and choose another item it needs to put the price of that item in the price_field.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
I appears you are trying to mix Javascript and PHP incorrectly.
PHP knows nothing about [this.options[this.selectedIndex].value].
may work but is a total mess for readability. (OK I can't be bothered to read it
)
even better would be something like...
This makes it far easier to debug.
PHP knows nothing about [this.options[this.selectedIndex].value].
Code: Select all
<select name=projectї<? echo $counter; ?>] onChange="document.formsї'frm_facaanmaken'].elementsї'project_verkoopprijsї<?echo $counter; ?>]'].value = <? echo "$verkoopprijs ?>їthis.optionsїthis.selectedIndex].value]";;" style="height:18;" height=24>even better would be something like...
Code: Select all
<?php
$change="document.forms['frm_facaanmaken'].elements['project_verkoopprijs[$counter]'].value = $verkoopprijs.[this.options[this.selectedIndex].value;";
echo("<select name="project[$counter]" onChange="$change" style="height:18;" height=24>");
?>Can you submit the values and change them into an array after receiveing them? That would be much easier if your project allows for that, if not, and you need them to send as an array.. take a look at your source code of the php document after it is sent to the browser (look at the html source it outputs), is there anything noticeably wrong with it?
Yeah...
Code: Select all
//get all your text field's values like this or _post or whatever you used
$var=$_GET['var'];
$thing=$_GET['thing'];
// Make a new array
$arr=array();
// Fill it in
$arr['thing']=$thing;
$arr['var']=$var;
// Test it out
echo "<pre>";
print_r ($arr);
echo "</pre>";Code: Select all
<?php
# $_POST[var];
# var is a array variable posted by prev page.
echo $_POST[var][0];
?>