我无法使用GET语法将从表单下拉列表中选择的多个字段存储到PHP中的变量。我正在根据选择在字段中执行搜索查询列表数据。
HTML code:
<html>
<body>
<form action="search3.php" method="GET">
<Table>
<tr>
<td>Transaction:</td>
<td>
<Select name="Transaction">
<Option value ="Buy">Buy</Option>
<Option value ="Sell">Sell</Option>
<Option value ="Rent">Rent</Option>
</select>
</td>
</tr>
<tr>
<td>PropertyType:</td>
<td>
<Select name="PropertyType">
<Option value ="Land">Land</Option>
<Option value ="Apartment">Apartment</Option>
<Option value ="Commercial">Commercial</Option>
<Option value ="Other">Other</Option>
</select>
</td>
</tr>
<tr>
<td>Location: </td>
<td>
<Select name ="Location">
<Option value ="Mumbai">Mumbai</Option>
<Option value ="Thane">Thane</Option>
<Option value ="NaviMumbai">NaviMumbai</Option>
<Option value ="Other">Other</Option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="submit"/></td>
</tr>
</Table>
</form>
</body>
</html>
PHP代码:
$Var2 = $_GET['PropertyType'];
$Var3 = $_GET['Location'];
$var1 = $_GET['Transaction'];
echo $var1;
echo $var2;
echo $var3;
$trimmed1 = trim($var1); //trim whitespace from the stored variable;
$trimmed2 = trim($var2); //trim whitespace from the stored variable;
$trimmed3 = trim($var3); //trim whitespace from the stored variable;
$db = "landshop_clientdata";
$link = mysql_connect('localhost','root');
if (!$link) {
die("Couldn't connect to MySQL");
}
mysql_select_db($db, $link)
or die("Couldn't open $db: ".mysql_error());
$result = mysql_query("SELECT Agent_Ind,Title,firstname,lastname,Phone,email,Transaction,propertyType,Location,Area,Units,AdditionalData FROM clientdata where Transaction ='$trimmed1' AND PropertyType = '$trimmed2' AND Location = '$trimmed3' AND '$trimmed2' AND '$trimmed3")
or die("SELECT Error: ".mysql_error());
//$describe = mysql_query("SHOW COLUMNS FROM $table")
//$meta = mysql_fetch_field($result);
//$fields_array[] = $meta->name;
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "These are records for $trimmed1.<p>";
//$row = mysql_fetch_assoc($result);
print "<table width=600 border=1>\n";
//while ($get_info = mysql_fetch_row($result))
//print "<tr>\n";
//foreach ($get_info as $field)
//print "<tr><td><font face=arial size=3/>name :</td> </tr>"
//print "<tr><td>$field</font></td></tr>";
Print "<th> Agent or Individual</th> ";
Print "<th> Title</th> ";
Print "<th> First Name</th> ";
Print "<th>Last Name</th>";
Print "<th> Phone</th> ";
Print "<th> Email</th> ";
Print "<th>Transaction</th>";
Print "<th> Location</th> ";
Print "<th> Area</th> ";
Print "<th> Units</th> ";
Print "<th> Additional_Data_of_Property</th> ";
while($info = mysql_fetch_array( $result ))
{
print "<tr>\n";
Print "<td>log in to see</td>\n";
Print "<td>log in to see</td>\n";
Print "<td>log in to see</td>\n";
Print "<td>log in to see</td>\n";
Print "<td>log in to see</td>\n";
Print "<td>log in to see</td>\n";
Print "<td>".$info['Transaction'] . " </td>\n";
Print "<td>".$info['Location'] . "</td>\n";
Print "<td>".$info['Area'] . "</td>\n";
Print "<td>".$info['Units'] . "</td>\n";
Print "<td width '80%'>".$info['AdditionalData'] . "</td>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
echo ("Want to view full contact details\n");
print( '<a href="index_files/logIn.htm">Login or Register</a>' );
echo ("Click to return to landshoppe\n");
print( '<a href="index.htm">Click Me</a>' );
答案 0 :(得分:0)
我相信您正在处理的问题是HTML“表单”通常使用POST数组(和后续命令),而不是“GET”请求。尝试检查要发布到的页面上的POST阵列。