I just stated learning PHP this morning and have come into a problem I cant get past. I think the problem is with my form but I am not sure.
I am writing an address book type app for my work and I have gotten everything working..ie pulling from DB, updating DB but I cant seem to run a search. Is there anything I am missing? Here is this code:
<?PHP
INCLUDE 'settings/connect.php';
INCLUDE 'include/functions.inc';
session_start();
top();
if (@$_GET['Action'] == "Search")
{
mysql_select_db("my_db", $conn);
$query = "select * from data where Number='$Number' and DID1='759' Order By Number";
echo "$query"; //Just have these here so I can see what query is being run. Nnot sure which one works.
echo $query;
$result = mysql_query($query) or die ("Couldn't execute SELECT query!");
echo "<div align='right'><a href='search.php'>Search Again</a></div>";
echo "<table border=1 width='600'><tr><td align='center' width='75'><b>Number</b></td><td align='center'><b>User</b></td><td align='center'><b>Data</b></td><td align='center'><b>Available</b></td><td align='center' width='45'><b>Type</b></td><td align='center' width='45'><b>Edit</b></td></tr>";
while ( $data = mysql_fetch_assoc($result))
{
extract($data);
echo "<tr>\n<td align='center'>".$Number."</td>\n";
echo " <td> ".$Name."</td>\n";
echo " <td align='center'>".$DID2." </td>\n";
echo " <td align='center'>".$Available." </td>\n";
echo " <td>";
If ($DID1 == '759')
{
echo " Fax";
}
else
{
echo " Phone";
}
echo "</td>\n";
echo " <td align='center'><a href='edit.php?Action=Edit&Number=".$Number."&DID=".$DID1."'>Edit</a></td>\n";
echo " </tr>\n";
}
}
else
{
echo "<p> <form action='search.php?Action=Search' method='POST'><table>\n";
echo "<tr><td colspan='2'>Search for: <input type='text' name='value' value='$Value'></td>\n";
echo "<td><input type='radio' name='type' value='UserS'>User </td>\n";
echo "<td><input type='radio' name='type' value='NumberS'>Phone Number</td></tr>\n";
echo "<tr><td colspan='3'><br><input type='hidden' name='Action' value='Search'>\n<input type='Submit' name='Submit' value='Search'></td><tr>\n";
echo "</table></form>";
}
foot();
?>
I tried having the following code where the select is but I cant even get it to run a query so i know it has lots of problems. Basicly I want the radio buttons to select which table field to search for data..... (replaces: $query = "select * from data where Number='$Number' and DID1='759' Order By Number"; )
if (@$_GET['type'] == 'UserS')
{
$query = "select * from data where Name='$Value' and DID1='759' Order By Number";
}
elseif (@$_GET['type'] == 'NumberS')
{
$Number = $_GET['Number'];
$query = "select * from data where Number='$Value' and DID1='759' Order By Number";
}
Any Ideas?
Thanks for the help,
Keith