This is the code which creates the dropdowns
/*------------------------------------------------------------------------
create the drop downs
------------------------------------------------------------------------*/
function dropdown($field, $table)
{
//initialize variables
$oHTML = '';
$result = '';
//check to see if the field is passed correctly
if (($field == "")||($table == ""))
{
die("No column or table specified to create drop down from!");
}
$sql = "select distinct($field) from $table";
//call the db function and run the query
$result = conn($sql);
//if no results are found to create a drop down return a textbox
if ((!$result) ||(mysql_num_rows($result)==0))
{
$oHTML .= "<input type='text' name='$field' value='' size='15'>";
}elseif (($result)&&(mysql_num_rows($result)>0)){
//build the select box out of the results
$oHTML .= "<select name='$field'>\n<option value='choose'>Choose</option>\n";
while ($rows = mysql_fetch_array($result))
{
$oHTML .= "<option value='".$rows[$field]."'>".$rows[$field]."</option>\n";
}
$oHTML .= "</select>\n";
}
//send the value back to the calling code
return $oHTML;
}//end function
The option 'choose' comes from this code. So I want the message displayed only if the returned value is equal to 0 and the 'choose' is not chosen from the dropdowns at the same time? How could I write that in php? I can't seem to figure it out :mad:
I meant of course mysql_real_escape_string() instead of addslashes() 🙂
But I would think I've got the connection open when this is on the same page
/*------------------------------------------------------------------------
database connection function
------------------------------------------------------------------------*/
function conn($sql)
{
$username = "*****";
$pwd = "*****";
$host = "localhost";
$dbname = "**";
//echo "commnecing connection to local db<br>";
if (!($conn=mysql_connect($host, $username, $pwd))) {
printf("error connecting to DB by user = $username and pwd=$pwd");
exit;
}
$db3=mysql_select_db($dbname,$conn) or die("Unable to connect to local database");
$result = mysql_query($sql) or die ("Can't connect because ". mysql_error());
return $result;
}//end function