/    Sign up×
Community /Pin to ProfileBookmark

try to pull info from mysql to drop down menu

i’m to do use a drop down menu to display data in sql database field username, this is the code i have at the moment, no errors but doesnt work either, any suggestions?

[QUOTE]

<?php

require(“auth_admin.inc.php”);
require(“../conn.inc.php”);

$sqlquery = “Select Username from User_Info”;

$sql_result = mysql_query($sqlquery) or die(“Couldn’t read from database, please contact your system administrator: $sqlquery – ” . mysql_error());

?>

<h3>Which User ID would you like to select?
<select name = “username” size=”1″>
<Option Value=” “>Select One:</option>
<?php

for($u=0;$u<mysql_num_rows($sqlquery); $u++) {
$Username=mysql_result(sqlquery,$u,’Username’);
?>

<option value=”<? echo($Username); ?>”><? echo($Username); ?>
</option>

</h3>

[/QUOTE]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@cafrowFeb 07.2006 — i'm to do use a drop down menu to display data in sql database field username, this is the code i have at the moment, no errors but doesnt work either, any suggestions?[/QUOTE]

[code=php]
<?php
require("auth_admin.inc.php");
require("../conn.inc.php");

$sqlquery = mysql_query("Select Username from User_Info");
?>

<h3>Which User ID would you like to select?</h3>
<select name = "username" size="1">
<Option Value=" ">Select One:</option>
<?php

while($row = mysql_fetch_array($sqlquery))
{
?>
<option value="<?=$row['Username']?>"><?=$row['Username']?></option>
<?php
}
?>
[/code]
Copy linkTweet thisAlerts:
@cashton2kauthorFeb 07.2006 — doesnt seem to work, i get the drop down menu but no data in it
Copy linkTweet thisAlerts:
@cashton2kauthorFeb 08.2006 — tried loads of changes but doesnt seem to work

current code

<?php

require("auth_admin.inc.php");

require("../conn.inc.php");

$sqlquery = "Select username from User_Info";

$sql_result = mysql_query($sqlquery) or die("Couldn't read from database, please contact your system administrator: $sqlquery - " . mysql_error());


?>

<html>

<head>

<title>I.P tutor >> Admin >> Messaging</title>

<link rel="stylesheet" href="../stylesheets/iptutorstyle.css" type="text/css">

</head>

<body>

<img border="0" src="../images/adminmessaging.jpg" width="600" height="44"><br>

<br>

&nbsp;<p>

<h3>Use this feature to send a message to an I.P Addressing Tutor user - sending a new message will overwrite a current one</h3>

<br>

</p>

<form action="sendmessage.php" method="post">

<h3>Which User ID would you like to select?</h3>

<select name = "username" size="1">

<Option Value=" ">Select One:</option>

<?php

while($row = mysql_fetch_array($sqlquery))

{

?>

<option value="<?=$row['Username']?>"><?=$row['Username']?></option>

<?php

}

?>

<input type="Submit" name="submit" value="Send">

<input type="Button" value="Cancel" name="cancel" onclick="history.go(-1)"></p>

</form>

</body>

</html>[/QUOTE]
Copy linkTweet thisAlerts:
@SheldonFeb 08.2006 — Try:
[code=php]
<?php
require("auth_admin.inc.php");
require("../conn.inc.php");
?>

<h3>Which User ID would you like to select?</h3>
<select name = "username" size="1" style="width:200px;">
<Option Value=" ">Select One:</option>
<?php
$t = "SELECT Username FROM User_Info ORDER BY Username ASC"; //May as well order the drop down list? yeah why not.
$s = mysql_query($t);
echo(mysql_error()); // if there is an error in my SELECT tell us about it

while($r = mysql_fetch_assoc($s)){
?>
<option value="<?php echo($r['Username']); ?>"><?php echo($r['Username']); ?></option>
<?php
//Some times php short tags are accepted by php/apache as proper php tags
}
?>

</select>
<input type="submit" value="Select User" style="width:200px;">
</form>
[/code]
×

Success!

Help @cashton2k spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...