dogugotw
10-23-2004, 10:20 PM
Noob alert.
What I'm trying to do
User sees a form, one field, select drop down box populated via a query against a MySQL db. This works (whoo whoo!).,
User selects a value, a second query is run using the selected value from the first query as the WHERE clause in the 2nd query.
If the selected value from Query1 is a single word, Query2 works like a charm.
If the selected value from Query1 has more than one word (and spaces), $site when echoed back to the screen is just the first word and Query2 results are null.
I know I'm missing something stupid but can't find it in any of the books, articles, forums, or googled searches I've tried. Any pointers or tips are greatly appreciated.
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 print results. This bit works great, list is what I expect to see.
$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>";
// if $site is one word, the rest of this works also.
// if $site is two words or more, I get the first word only and the 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>
What I'm trying to do
User sees a form, one field, select drop down box populated via a query against a MySQL db. This works (whoo whoo!).,
User selects a value, a second query is run using the selected value from the first query as the WHERE clause in the 2nd query.
If the selected value from Query1 is a single word, Query2 works like a charm.
If the selected value from Query1 has more than one word (and spaces), $site when echoed back to the screen is just the first word and Query2 results are null.
I know I'm missing something stupid but can't find it in any of the books, articles, forums, or googled searches I've tried. Any pointers or tips are greatly appreciated.
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 print results. This bit works great, list is what I expect to see.
$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>";
// if $site is one word, the rest of this works also.
// if $site is two words or more, I get the first word only and the 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>