/    Sign up×
Community /Pin to ProfileBookmark

drop down menu help

I have a page that list movies, directors, and actors. I can add, edit, and delete. Right now I’m working on editing the people. I can get the form to display with all the data, but I’m having trouble with the processing of this data before I update the database. Here is my entire code.

<?php
require_once (‘dbconnection.php’);

$query = “SELECT * FROM people”;
$result = mysql_query($query) or die (mysql_error());

//compare id to name
//array of id and names
while ($row = mysql_fetch_array($result))
{
$people[$row[‘people_id’]] = $row [‘people_fullname’];
}

//either populate fields from db or display empty fields
switch ($_GET[‘action’])
{
case “edit”:
$q = “SELECT * FROM people
WHERE people_id = ‘”.$_
GET[‘id’].”‘”;
$r = mysql_query($q) or die (mysql_error());
$row1 = mysql_fetch_array($r);

$people_fullname = $row1[‘people_fullname’];
$people_isactor = $row1[‘people_isactor’];
$people_isdirector = $row1[‘people_isdirector’];
break;

default:
$people_fullname = “”;
$people_isactor = “”;
$people_isdirector = “”;
break;

}
?>

<html>
<head>
<title><?php echo $_GET[‘action’];?>people</title>
<style type = “text/css”>
TD{color:#353535; font-family:verdana}
TR{color:#FFFFFF; font-family:verdana; background-color:#336699}
</style>
</head>
<body>
<center>1 = yes 0 = No</center>
<form action=”commit.php?action=
<?php echo $_
GET[‘action’];?>&type=people&id=
<?php echo $_GET[‘id’];?>” method =”post”>
<table border=”0″ width=”750″ cellspacing=”1″ cellpadding=”3″ bgcolor=”#353535″ align=”center”>
<tr>
<td bgcolor=”#FFFFFF” width=”30%”>Person Name</td>
<td bgcolor=”#FFFFFF” width=”70%”>
<input type=”text” name=”people_fullname”
value=”<?php echo $people_fullname ?>”>
</td>
</tr>

<tr>
<td bgcolor=”#FFFFFF”>Actor</td>
<td bgcolor=”#FFFFFF”>

<select name=”people_isactor” style=”width:150px”>
<option value=”yes”>Yes</option>
<option value=”no”>No</option>

<?php

[B]if ($_POST[‘people_isactor’] == “yes”)
{
$people_isactor = 1;
}
else
{
$people_isdirector = 0;
}[/B]

?>
</select>
</td>
</tr>

<tr>
<td bgcolor=”#FFFFFF” colspan=”2″ align=”center”>
<input type=”submit” name=”SUBMIT” value=”<?php
echo $_GET[‘action’];?>”>
</td>
</tr>

</table>
</form>
</body>
</html>

I’m having trouble with the if statement below the <select> No matter what option I choose it always reads false. My database is set up so an actor is 1 and director is 0 for one person. The next person might be a director so director is set to 1 and actor is set to 0

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@zombieJonesMar 28.2008 — The way you have it says: if Yes, then Actor. if No, then [I]Not[/I] Director (ie Actor again)

Shouldn't it be more like:

if ($_POST['people_isactor'] == "yes")

{

$people_isactor = 1;

$people_isdirector = 0;

}

else

{

$people_isdirector = 1;

$people_isactor = 0;

}
[/QUOTE]

Or with just the one variable. people_isactor it would work fine too.
×

Success!

Help @purplelotus 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.24,
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,
)...