SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Jun 7, 2007, 05:58 #1
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
select statement not keeping the variable
I have a select function that looks like this:
PHP Code:<?
$db_host = "1234";
$db_user = "1234";
$db_pwd = "1234";
$db_name = "1234";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
$sql = "SELECT username, firstname, lastname FROM authorize ";
$result = mysql_query($sql);
?>
<form action="mod2.php" method="post">
<select name="username">
<?
while($row=mysql_fetch_assoc($result))
{
$username = $row['username'];
$name = $row['firstname']." ".$row['lastname'];
echo "<option value=\"$username\">$name</option>";
}
?>
</select>
<input type="submit" value="Submit" name="submit" />
</form>
PHP Code:<?php
$userid = $_POST['username'];
?>
<?php
$con = mysql_connect("1234","1234","1234");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('1234', '$con');
$result = mysql_query("SELECT firstname FROM authorize
WHERE username='$userid'");
while($row = mysql_fetch_array($result))
{
echo $row['firstname'];
}
?>
-
Jun 7, 2007, 06:05 #2
$result = mysql_query("SELECT firstname FROM authorize
WHERE username='$userid'
LIMIT 1
");
...
while($row = mysql_fetch_assoc($result))
{
echo $row['firstname'];
}
-
Jun 7, 2007, 06:20 #3
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Still showing a blank page after making the changes above.
-
Jun 7, 2007, 08:27 #4
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Do you remember from the last thread about doing debugging through the script?
PHP Code:$userid = $_POST['username'];
// debug variable, does it show?
echo $userid;
$sql = "SELECT firstname FROM authorize
WHERE username='$userid'";
echo $sql; // does it look right?
$result = mysql_query($sql) or die(mysql_error());
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jun 7, 2007, 08:33 #5
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the problem was here
PHP Code:mysql_select_db('1234', '$con');
PHP Code:mysql_select_db('1234', $con);
-
Jun 7, 2007, 08:39 #6
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
Bookmarks