same errors basically, invalid resource, on your querys add OR die("error with query -- ".mysql_error());
it will dump the error from mysql so you can troubleshoot your statements
same errors basically, invalid resource, on your querys add OR die("error with query -- ".mysql_error());
it will dump the error from mysql so you can troubleshoot your statements
Can you explain what "Invalid resource" means.
I tried the or die statement but am not really any wiser. It says I have an incorrect database name, which is not true as the chemical drop down uses the same database. I've checked the SQL query and that seems all correct.
So I'm not sure where to go from here.
show your full code?
<?php
$Host = "";
$User = "";
$Password = "";
$DBName = "";
$Link = mysql_connect($Host, $User, $Password) or die(mysql_error());
?>
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM NAME="frmPump" METHOD="post" ACTION="phpbuilder6.php">
<TABLE WIDTH="360" BORDER="0" CELLPADDING="4" CELLSPACING="0" BORDERCOLOR="#FFFFFF" BGCOLOR="#CCCCCC">
<TR>
<TD WIDTH="101" CLASS="copy"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">First
choice</font></TD>
<TD width="243" ALIGN="center">
<SELECT NAME="chemical" SIZE="1" class="submit" ID="chemical" ONCHANGE="javascript:frmPump.submit()">
<OPTION SELECTED>Please choose a chemical</OPTION>
<?php
$qry1 ="SELECT chem_description FROM chemicals";
$res1 = mysql_db_query ($DBName,$qry1,$Link);
while ($row = mysql_fetch_array ($res1))
{
$selected = ($chemical == $row['chem_description'])?'selected':'';
echo"<OPTION VALUE ='{$row['chem_description']}'{$selected}>{$row['chem_description']}</OPTION>";
}
mysql_free_result($res1);
?>
</SELECT>
</TD>
</TR>
</TABLE>
<br>
<TABLE WIDTH="360" BORDER="0" CELLPADDING="4" CELLSPACING="0" BORDERCOLOR="#FFFFFF" BGCOLOR="#CCCCCC">
<TR>
<TD WIDTH="101" CLASS="copy"> <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Second
choice</font></TD>
<TD width="243" ALIGN="center">
<SELECT NAME="concentration" class="submit" ID="concentration" ONCHANGE="javascript:frmPump.submit()">
<OPTION SELECTED> Please choose a Concentration </OPTION>
<?php
if($chemical!="")//If not blank, then selection has been made
{
printf("<select name=\"concentration\" size=1 onChange=\"javascript:frmPump.submit()\">\n");
$qry2="SELECT conc_description FROM concentration WHERE concentration.chem_id = chemicals.chem_id";
$res2=mysql_db_query($qry2,$DBname);}
while ($row = mysql_fetch_array ($res2));
{
$selected = ($concentration == $row['conc_description'])?'selected':'';
echo"<OPTION VALUE='{$row['conc_description']}'{$selected}>{$row['conc_description']}</OPTION>";
}
mysql_free_result($res2) or die("mysql_free_result($res2)".mysql_error());
?>
</SELECT>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
you never assign $DBname or select the DB you want to use after you connect....
Could you expand a little. Which line are we talking about? I'm afraid this is the first bit of PHP I've had to do.
Originally posted by andynightingale
Could you expand a little. Which line are we talking about? I'm afraid this is the first bit of PHP I've had to do.
you assign $DBName = "";
and then tried usingin it mysql_db_query($DBName, $query, $Link);
$Link gets defined, $query gets defined but $DBName still equals ""
so you arent specifying WHAT database to query...
$DBName = "mydatabasename";
connect script assigns the database name to the variable $DBName
OK
$res1 = mysql_db_query($DBName,$qry1,$Link);
$res2 = mysql_db_query($DBname,$qry2,$Link);
Aren't the above querying $DBName, not re-assigning it?
Still confused
should work then yes....
Couldnt hurt to use mysql_select_db() though and mysql_query() just to alleviate the possibility that its erroring there...
I have just moved the test page and db from my test site to the actual site and it has stopped working
See:
http://www.ipixels.co.uk/swift_pumps/pump.php
then:
http://www.signal-pumps.co.uk/html/pumps_selection/pump.php
It can obviously see the db and execute the php as it pulls in the initial drop values. It refreshes to itself, so no path issues.
Any ideas?
If the value of Chemical is not being posted via the form, it could be because the "register_globals" attribute within the php.ini file is set to off. This is the default option since PHP 4.2.0.
You will either need to set the attribute to "on", or use the superglobal $POST (e.g. $POST["Chemical"]) when referencing the posted variables.
I know I'm being dumb, but where does the $_POST go?
if ($Chemical=="") {
printf("<option value=\"\" selected>Select A Chemical</option>");
} else {
printf("<option value=\"\">Select A Chemical</option>");
}
$qry = "SELECT DISTINCT Chemical FROM Pump ORDER BY Chemical";
$res = mysql_query($qry, $db);
for ($i=0; $i < mysql_num_rows($res); $i++) {
$row = mysql_fetch_array($res);
if ($Chemical==$row["Chemical"]) {
printf("<option value=\"%s\" selected>%s</option>", $row["Chemical"], $row["Chemical"]);
} else {
printf("<option value=\"%s\">%s</option>", $row["Chemical"], $row["Chemical"]);
}
}
mysql_free_result($res);
printf("</select><br><br></td></tr>\n");
if ($_POST["Chemical"]=="") {
printf("<option value=\"\" selected>Select A Chemical</option>");
} else {
printf("<option value=\"\">Select A Chemical</option>");
}
$qry = "SELECT DISTINCT Chemical FROM Pump ORDER BY Chemical";
$res = mysql_query($qry, $db);
for ($i=0; $i < mysql_num_rows($res); $i++) {
$row = mysql_fetch_array($res);
if ($_POST["Chemical"]==$row["Chemical"]) {
printf("<option value=\"%s\" selected>%s</option>", $row["Chemical"], $row["Chemical"]);
} else {
printf("<option value=\"%s\">%s</option>", $row["Chemical"], $row["Chemical"]);
}
}
mysql_free_result($res);
printf("</select><br><br></td></tr>\n");
Pete, where am I going wrong? I know its in the $qrym = "SELECT.... line
ps. did you sort out your photoshop/quark/illustrator query?
andy
[code=php]if ($_POST["Chemical"]!="") {
printf("<tr><td width=150>Concentration List</td><td><select name=\"Concentration\" size=1 onChange=\"frmPump.submit()\">");
if ($_POST["Concentration"]=="") {
printf("<option value=\"\" selected>Select A Concentration</option>");
} else {
printf("<option value=\"\">Select A Concentration</option>");
}
$qry = "SELECT DISTINCT Concentration FROM Pump WHERE Chemical='($_POST["Chemical"])'";
$res = mysql_query($qry, $db);
for ($i=0; $i < mysql_num_rows($res); $i++) {
$row = mysql_fetch_array($res);
if ($_POST["Concentration"]==$row["Concentration"]) {
printf("<option value=\"%s\" selected>%s</option>", $row["Concentration"], $row["Concentration"]);
} else {
printf("<option value=\"%s\">%s</option>", $row["Concentration"], $row["Concentration"]);
}
}
mysql_free_result($res);
printf("</select><br><br></td></tr>\n");
}[/code]
Try the following:
$qry = "SELECT DISTINCT Concentration FROM Pump WHERE Chemical='" . $_POST["Chemical"] . "'";
It might have been the case of it getting confused with the single/double quotes.
And I have sorted the photoshop/quark/illustrator query - hopefully I can get the place of work I'm at to send on some courses.
Cheers !
Thanks Pete, that works. I've really got to study my syntax!