/    Sign up×
Community /Pin to ProfileBookmark

I should be able to do this, but…

Ok, I have this little bit of php code:

[code=php]
<?php
$query = “SELECT Company FROM Customer WHERE Sales_Rep = ‘$salesrep’;”;
$result = mysql_query($query) or die(“SQL Error: ” . $query . “<br>” . mysql_error());

$msg .= “<form enctype=’application/x-www-form-urlencoded’ method=’post’ target='<?php echo $_SERVER[‘PHP_SELF’]; ?>’>”;
$msg .= “<select name=’clients’ id=’clients’>”;
while ($row = mysql_fetch_assoc($result)) {
//$msg .= “<div class=’account’>”;
foreach ($row as $key => $val) {
//$msg .= “<span class=’act’>”.$key.” :</span><span class=’acp’>”.$val.”</span><br/>”;
$msg .= “<option value='”$val”‘ >”$val”</option>”;
}
//$msg .= “</div>”;
}
$msg .= “</select>”;
$msg .= “</form>”;
?>
[/code]

Which I am trying to get to populate a select list with the specific value from the mysql table. The code that is commented out works fine but I want to be able to make a selection list, not just a list of the data in a page, so that I can then select a specific value and do stuff with the other data associated with it. Follow what I am trying to do?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ZnupiMar 19.2007 — You have some errors
[code=php]
$msg .= "<form enctype='application/x-www-form-urlencoded' method='post' target='<?php echo $_SERVER['PHP_SELF']; ?>'>";
// The above shoud be...
$msg .= "<form enctype='application/x-www-form-urlencoded' method='post' target='" . $_SERVER['PHP_SELF'] . "'>";
[/code]

And...
[code=php]
$msg .= "<option value='"$val"' >"$val"</option>";
// The above should be ...
$msg .= "<option value='" . $val . "' >" . $val . "</option>";
[/code]

And no, I'm not following what you're trying to do :-/
Copy linkTweet thisAlerts:
@polorboyauthorMar 19.2007 — Those stinking dots, I always forget those.
Copy linkTweet thisAlerts:
@ZnupiMar 19.2007 — Works now?
Copy linkTweet thisAlerts:
@bokehMar 19.2007 — [code=php]
$msg .= "<form enctype='application/x-www-form-urlencoded' method='post' target='<?php echo $_SERVER['PHP_SELF']; ?>'>";
// The above shoud be...
$msg .= "<form enctype='application/x-www-form-urlencoded' method='post' target='" . $_SERVER['PHP_SELF'] . "'>";
[/code]
[/QUOTE]

if you are going to submit a form to itself just use an empty string as the argument to the action attribute.[code=html]<form action="" method="post">[/code]
Copy linkTweet thisAlerts:
@polorboyauthorMar 20.2007 — Ok, I got it to work. For some reason it would not work if I had the php generate all of the form code, but when I had it just generate the <option> tags it works fine.
×

Success!

Help @polorboy 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.18,
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,
)...