0
我無法使用GET語法將多個從字段下拉列表中選擇的字段存儲到PHP中的變量中。我正在根據選擇在字段中執行搜索查詢列表數據。無法將選擇的字段從下拉列表存儲到變量
HTML代碼:
<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>');
顯示您的代碼:) – 2011-04-06 06:26:09
請粘貼代碼片段..我們不是魔術師 – diEcho 2011-04-06 06:28:02
是你使用通用代碼:D – 2011-04-06 06:28:35