Page 2 of 2
Posted: Thu Sep 06, 2007 4:52 am
by pyoungson
Now I get the following:
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.
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.
Posted: Thu Sep 06, 2007 5:17 am
by CoderGoblin
That's what we wanted..
Now change
Code: Select all
if ( isset($_POST['Solvents']) ) {
$_POST['Solvents'] = implode('\', \'', $_POST['Solvents']);
}
to
Code: Select all
if ( isset($_POST['Solvents']) ) {
$SolventList = implode('\', \'', $_POST['Solvents']);
}
and in your SQL statement
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']}')
)");
to
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}')
)");
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.
Posted: Thu Sep 06, 2007 5:33 am
by pyoungson
I do not understand why but it does not see SolventList as a variable:
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'];
}
I now get the following:
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
Posted: Thu Sep 06, 2007 6:08 am
by CoderGoblin
No idea why $SolventList is not set... Will need to test and unfortunately haven't the time at present.
What happens if you change
Code: Select all
if ( isset($_POST['Solvents']) ) {
$SolventList = implode('\', \'', $_POST['Solvents']);
}
to
Code: Select all
if ( isset($_POST['Solvents']) ) {
$SolventList = implode("', '", $_POST['Solvents']);
echo "DEBUG --- Solvent id set";
}
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.
Posted: Thu Sep 06, 2007 6:58 am
by pyoungson
Nothing happens if I make that change unfortunately. Thank you for your help so far, I wouldn't have got this far on my own.
Posted: Thu Sep 06, 2007 7:14 am
by Stryks
The reason that $SolventList is not being set is because there is no 'check_submit' key in the $_POST array ... hence the "You can't see this page without submitting the form." being displayed.
You didn't happen to remove the hidden "check_submit" field from your form did you?
Posted: Thu Sep 06, 2007 7:19 am
by Stryks
It might be easier to just change your submit button to something like ...
Code: Select all
<input type="submit" name="submit" value="1" />
You can then do ...
Code: Select all
if (array_key_exists('submit', $_POST)) {
... and lose the hidden field altogether. I'm not sure if you even have to set the value.