/    Sign up×
Community /Pin to ProfileBookmark

I have a landing page that displays movies and people. I can add, edit, or delete. I’m trying to edit the people. I can get the form to display but I’m having a hard time getting the changes to process. Here is my 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

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

?>
</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 having trouble with the if statment after the <select> No matter what I choose in the drop down box the if statement always returns false.
I store the peole in my database. The first person may be an actor so i set the actor field to 1 and director field to 0. Right now I’m focusing on the actor portion and then I’ll do the director.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@SyCoMar 28.2008 — Your <form> tag is a bit wierd

action="commit.php?action=

<?php echo $_GET['action'];?>&type=people&id=

<?php echo $_
GET['id'];?>"

I presume this code is from the script commit.php? The action of the form and the GET vars are coming form the URL but why do you have them as get vars in the action when the method of the form is post?

If you need to pass extra info back to the page use hidden fields.

[code=php]<form action="commit.php" action="post">
<input type="hidden value="<?=$_GET['action']?>">[/code]

etc

notice the shorthand echo <?= ?> too that helps keep the code readable.

So there is no post on the page when you first get there so it will be false. Where that form is going I don't know. Basically you need to tidy it up.

Can you use [code=php][/code] tags around your code too please.
×

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.14,
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,
)...