However I now get no value for the maxdispersive so the above array can not be in the form to get anything from the mysql. I'm getting very confused about what exact input is wanted.Array ( [Solvents] => Array ( [Vinyl S-ethyl mercapto ethyl ether] => Vinyl S-ethyl mercapto ethyl ether [Vinyl trifluoro acetate] => Vinyl trifluoro acetate [Vinyl-2-ethyl hexanoate] => Vinyl-2-ethyl hexanoate [Water] => Water ) ) You can't see this page without submitting the form.
Populating checkboxes using php
Moderator: General Moderators
Now I get the following:
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
That's what we wanted..
Now change to
and in your SQL statement to
The problem you are having is two fold.
First Solvent without setting it as an array in HTMLwill only store 1 value (the last set) hence the [] on the name. I included the name as an index purely to check what we are getting. It is prefectly OK to have it as name="Solvent[]".
Second problem is that $_POST is readonly. You cannot set it to something different.
Now change
Code: Select all
if ( isset($_POST['Solvents']) ) {
$_POST['Solvents'] = implode('\', \'', $_POST['Solvents']);
}Code: Select all
if ( isset($_POST['Solvents']) ) {
$SolventList = implode('\', \'', $_POST['Solvents']);
}Code: Select all
$dispersive = mysql_query("select name, dispersive as max_dispersive
from solvents
where name in('{$_POST['Solvents']}')
and dispersive = ( select max(dispersive)
from solvents
where name in('{$_POST['Solvents']}')
)");Code: Select all
$dispersive = mysql_query("select name, dispersive as max_dispersive
from solvents
where name in('{$_POST['Solvents']}')
and dispersive = ( select max(dispersive)
from solvents
where name in('{$SolventList}')
)");First Solvent without setting it as an array in HTMLwill only store 1 value (the last set) hence the [] on the name. I included the name as an index purely to check what we are getting. It is prefectly OK to have it as name="Solvent[]".
Second problem is that $_POST is readonly. You cannot set it to something different.
I do not understand why but it does not see SolventList as a variable:
I have changed the code in the way you noted:
I now get the following:
I have changed the code in the way you noted:
Code: Select all
<?php
print_r($_POST);
if (array_key_exists('check_submit', $_POST)) {
if ( isset($_POST['Solvents']) ) {
$SolventList = implode('\', \'', $_POST['Solvents']);
}
} else {
echo "You can't see this page without submitting the form.";
}
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("solvents", $con);
$result = mysql_query("SELECT * FROM solvents WHERE Name
IN('{$_POST['Solvents']}')");
$dispersive = mysql_query("select name, dispersive as max_dispersive
from solvents
where name in('{$_POST['Solvents']}')
and dispersive = ( select max(dispersive)
from solvents
where name in('{$SolventList}')
)");
while($row = mysql_fetch_array($dispersive))
{
$maxdispersive = $row['max_dispersive'];
}Array ( [Solvents] => Array ( [Vinyl S-ethyl mercapto ethyl ether] => Vinyl S-ethyl mercapto ethyl ether [Vinyl trifluoro acetate] => Vinyl trifluoro acetate [Vinyl-2-ethyl hexanoate] => Vinyl-2-ethyl hexanoate [Water] => Water ) ) You can't see this page without submitting the form.
Notice: Undefined variable: SolventList in C:\ I have edited this out \process1.php on line 32
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
No idea why $SolventList is not set... Will need to test and unfortunately haven't the time at present.
What happens if you change
to
You would also need to change all your "IN ($_POST['Solvent']) queries to $SolventList when you get it working not just the one I did previously.
What happens if you change
Code: Select all
if ( isset($_POST['Solvents']) ) {
$SolventList = implode('\', \'', $_POST['Solvents']);
}Code: Select all
if ( isset($_POST['Solvents']) ) {
$SolventList = implode("', '", $_POST['Solvents']);
echo "DEBUG --- Solvent id set";
}It might be easier to just change your submit button to something like ...
You can then do ... ... and lose the hidden field altogether. I'm not sure if you even have to set the value.
Code: Select all
<input type="submit" name="submit" value="1" />Code: Select all
if (array_key_exists('submit', $_POST)) {