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($qu ery, $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>Th e requested site is $site <br><br>";
echo "<table border=1>\n";
echo "<tr><td>Th e username is:</td><td>The password is:</td>";
$query2 = "Select * from sitelogins where site = '$site'";
$result2 = mysql_query($qu ery2, $db);
if(!$result2) die ("query failed");
while($row = mysql_fetch_row ($result2)) {
echo "<tr><td>$r ow[1]</td><td>$row[2]</td></tr>";
}
echo "</table>";
// close connnection
mysql_close($db );
?>
<br>
<input type="submit" value = "Get Password">
</form>
</html>
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($qu ery, $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>Th e requested site is $site <br><br>";
echo "<table border=1>\n";
echo "<tr><td>Th e username is:</td><td>The password is:</td>";
$query2 = "Select * from sitelogins where site = '$site'";
$result2 = mysql_query($qu ery2, $db);
if(!$result2) die ("query failed");
while($row = mysql_fetch_row ($result2)) {
echo "<tr><td>$r ow[1]</td><td>$row[2]</td></tr>";
}
echo "</table>";
// close connnection
mysql_close($db );
?>
<br>
<input type="submit" value = "Get Password">
</form>
</html>
Comment