/    Sign up×
Community /Pin to ProfileBookmark

Form Action Variable using PHP

Can anyone please help me – I am trying to set a form action variable based on a held value in a mySQL database.

Here is my code to selec the code from the table and then an if/else if statement to set the action variable:

$query = “SELECT code FROM table WHERE name = ‘$name'”;
$result = mysql_query($query) or die (“MySQL error: $query. ” . mysql_error());
while ($myrow = mysql_fetch_array($result)) {
$code = ($myrow[“code”]);
if ($code==”s”)
$action=”sss.php”;
else if ($code==”t”)
$action=”ttt.php”;
}

Then my form HTML code is:
<form action=”<? echo $action; ?>” method=”post”>

This partially works as my form action is always sss.php – even where the code is s or t. Can anyone offer some ideas for me please ??????

Paul

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsMar 11.2006 — [code=php]$query = "SELECT code FROM table WHERE name = '$name'";
$result = mysql_query($query) or die ("MySQL error: $query. " . mysql_error());
$myrow = mysql_fetch_assoc($result);
$code = $myrow["code"];

if ($code == "s") $action = "sss.php";
else if ($code == "t") $action = "ttt.php";[/code]


No guarantees, but the problem is probably caused by the looping, so try that above.
×

Success!

Help @paulb 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.22,
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,
)...