HELP! Urgent... Using php with forms and database...
Posted: Wed Jul 23, 2003 3:18 am
hi.. I'm new at php.. got stuck wif something.. it's kinda urgent..
the idea:
1) have a form wif a text box.. enter a prod_name ($form[prod_id])
2) then retrieve and display the prod_id of tht prod_name from the database..
I do know how to do a textbox and take the value.. Then here's the prob.. I'm not very good at retrieving from the database..
this i know:
connecting;
then I'm not sure on how to retrieve and display the prod_id from the function.. and not sure if this is correct.. Can anyone help? Thanks.. 
the idea:
1) have a form wif a text box.. enter a prod_name ($form[prod_id])
2) then retrieve and display the prod_id of tht prod_name from the database..
I do know how to do a textbox and take the value.. Then here's the prob.. I'm not very good at retrieving from the database..
this i know:
connecting;
Code: Select all
їphp]<?php
$prod = getProd("product"); // this is a function
// how to retrieve the results and display the prod_id of the prod_name/
?>ї/php]Code: Select all
їphp]<?php
//this is the getProd function
function getProd($table)
{
global $prod_link;
$query = "SELECT * from $table ORDER BY prod_name";
$result = mysql_query($query, $prod_link);
if ( ! $result)
{
print "failed to open $table<p>";
return false;
}
$ret=array();
$temp="";
while($row=mysql_fetch_array($result))
{
// if the prod name not blank.. and the prod family is not special
if($rowїprod_name]!=$temp && $rowїprod_family]!="special")
{
$rowїprod_name]=$rowїprod_name];
array_push($ret,$row);
}
$temp=$rowїprod_name];
}
return $ret;
}
?>ї/php]