问题描述
Noob提醒。
代码如下。
文件保存为.php。
我是什么我试图这样做:
用户使用''选择''框下拉列表来选择一个值。
值($ site)来自db查询。这很好。
选择的值用作第二个查询的''where''子句。
如果$ site是一个单词,第二个查询就像一个魅力。
如果$ site不止一个单词(有空格),查询返回一个空的
因为$ site被修剪回第一个单词(I可以告诉那个
,因为我回应了$ site的价值。
我在这里戳了一下,谷歌搜索但没有快乐。任何提示都是
赞赏.Sooo关闭...
Doug
< html>
< body>
从下面的列表中选择网站名称< br>
注意 - 如果您开始输入名称,则无需滚动到
名称。< br>
< / body>
< br>
< form> ;
<?php
//定义变量
$ server =''localhost'';
$ username =''web'';
$ password =''u ser'';
$ database =''HomeData'';
// $ query ="从sitelogins网站选择网站,用户名和密码=
''$ site''" ;;
$ query ="从网站按顺序从sitelogins中选择网站;
//连接到mysql
$ db = mysql_connect($ server,$ username,$ password);
//连接到db
mysql_select_db($ database,$ db);
//>>>>>运行查询并填充选择框 - 这个位很好。
//>>>>>请注意,如果我使用\$ site \下面,我什么都没得到。使用网站作为
名称似乎有效。
$ result = mysql_query($ query,$ db);
echo "< select name = \" site \">" ;;
if(!$ result)die(" query failed");
while($ row = mysql_fetch_row($ result)){
echo"< OPTION VALUE ="。$ row [0]。">"。$ row [0 ]。"< / OPTION>" ;;
}
echo"< / select>" ;;
//>>>>>下一行 - 如果$ site的值类似于''fred joe'',那么
echo $ site打印为''fred'',第二个查询返回null
echo"< br>< br>请求的网站是$ site< br>< br>";
echo"< table border = 1> \ n" ;;
echo"< tr>< td>用户名为:< / td>< td>密码为:< / td>" ;
$ query2 =" select * from sitelogins where site =''$ site''" ;;
$ result2 = mysql_query($ query2,$ db);
if(!$ result2)die(query failed);
while($ row = mysql_fetch_row($ result2)){
echo"< tr>< td> $ row [1]< / td>< td> $ row [2]< / td>< / tr>" ;;
}
echo"< / table>" ;;
// close connnection
mysql_close($ db);
?>
< br>
< input type =" submi T" value ="获取密码"
< / form>
< / html>
Noob alert.
Code is below.
File is saved as a .php.
What I''m trying to do:
User uses ''select'' box drop down list to pick a value.
Value ($site) is derived from a db query. This works fine.
Value selected is used as the ''where'' clause of the 2nd query.
If $site is a single word, the 2nd query works like a charm.
If $site is more than one word (has spaces), the query returns a null
because $site is trimmed back to just the first word (I can tell that
because I echo the value of $site.
I''ve poked around here and googled but no joy. Any tips are
appreciated. Soooo close...
Doug
<html>
<body>
Select the site name from the list below<br>
Note - if you start typing the name, you don''t have to scroll to the
name.<br>
</body>
<br>
<form>
<?php
// Define variables
$server = ''localhost'';
$username = ''web'';
$password = ''user'';
$database = ''HomeData'';
//$query = "Select site, username, password from sitelogins where site =
''$site''";
$query = "Select site from sitelogins order by site";
// connect to mysql
$db = mysql_connect($server, $username, $password);
// connect to db
mysql_select_db($database, $db);
// >>>>> run query and populate the select box - this bit works great.
// >>>>> note, if I use \"$site\" below, I get nothing. using site as
the name seems to work.
$result = mysql_query($query, $db);
echo "<select name=\"site\">";
if(!$result) die ("query failed");
while($row = mysql_fetch_row($result)) {
echo "<OPTION VALUE=".$row[0].">".$row[0]."</OPTION>";
}
echo "</select>";
// >>>>> next line - if the value of $site is something like ''fred joe'',
the echo $site prints as ''fred'' and the 2nd query returns null
echo "<br><br>The requested site is $site <br><br>";
echo "<table border=1>\n";
echo "<tr><td>The username is:</td><td>The password is:</td>";
$query2 = "Select * from sitelogins where site = ''$site''";
$result2 = mysql_query($query2, $db);
if(!$result2) die ("query failed");
while($row = mysql_fetch_row($result2)) {
echo "<tr><td>$row[1]</td><td>$row[2]</td></tr>";
}
echo "</table>";
// close connnection
mysql_close($db);
?>
<br>
<input type="submit" value = "Get Password">
</form>
</html>
推荐答案
这篇关于双查询表单,第一个查询的结果在空格后丢弃任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!