I want to get the name from a form.. Check if it exists in the database.. If it does.. push it into an array and display.. Then when i get back to the form... I do everything all over again.. push it into the array.. And when it displays.. i'd like both the first name and the second name entered to be pushed and displayed from the array..
Currently.. It only displays the latest one..
Can any one correct me? I can't seem to find out what's wrong..
Code: Select all
<?php
// retrieve the array from the session n display..
session_start();
$arr_unserial = unserialize($_session[searcharr]);
foreach($arr_unserial as $sess)
{
print "session arr:$sess";
}
$prods = getProd("product"); // retrieve the products from the database
$prod=array();
global $search_arr;
$search_arr=array(); // to store the prod_names that need to be searched
// Gets product names and pushes into array
foreach($prods as $prod_row)
{
if($prod_row[prod_family]!="special")
{
$prod_row[prod_name]=makealias($prod_row[prod_name]);
array_push($prod,$prod_row);
}
}
print "<html><head>
<title></title>
</head><body>
<blockquote>";
// Text field to search the prod name
print "<table border=0>";
print "<tr><td>";
print "<form action= $PHP_SELF name=selectprod>";
html_hidden("actionflag","selection");
print "<b>Search: </b>";
//text box
html_text("form[prod_name]");
print " ";
html_submit("","Ok");
print "</form>";
print "</td></tr>";
print "</table> <br>";
print "<hr>";
// Textfield search Action
if (isset($actionflag) && $actionflag =="selection") // check action flag
{
if($form[prod_name]!=null) // check if textfield not null
{
print "text search entered: $form[prod_name]<br><br>";
// Check if the product name entered is correct
foreach($prods as $prod_row)
{
if($form[prod_name] == $prod_row[prod_name]) // Product name entered matches
{
$matched = $form[prod_name];
print "$prod_row[prod_name] [matches] $matched<br>";
break;
}
else // Product name entered does not match
{
$matched = "not exist";
}
}
}
else
{
print "";
}
}
// Push into array
if($matched!=null && $matched!="not exist")
{
array_push($search_arr,$matched);
foreach($search_arr as $searched)
{
print "search_arr: $searched<br>";
}
}
// sessions
if($PHPSESSID && $matched!=null && $matched!="not exist")
{
$arr_serial = serialize($search_arr);
print "$sessarr<br>";
print "Session started<br>";
session_start(); // Start the session
$_session[searcharr] = $arr_serial;
print "$_session[searcharr]<BR>";
}
print "</blockquote>
</body> </html>";
?>