Jump to content

drop down menu


Ruth

Recommended Posts

I'm tying to perform an edit and add page regarding movies. My form has a text field for the actors name and two drop down menus to display if that person is an actor or director. I'm having a hard time with the drop down menus. I get the actor menu to display but when it comes to editing the if statement does not  work.

 

<?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">

 

<?php

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

{

    $isactor = 1;

}

else

}

  $isactor = 0;

}

 

the database hold actor as 1 if they are an actor and director as 0 if they are not a director. I need to be able to perform an update query on this.

Link to comment
Share on other sites

One: enclose everything [ code ] [ /code ] to make it easier to navigate.

 

Two: What 'if' isn't working?

 

Why would $_POST be populated it a submit button hadn't been hit?

 

I think you need to learn to walk before you run... play around with this script a bit.

 

<?php

if ($_POST['submit']) {

echo '<pre>Variable dump for $_POST' . "\n";
print_r($_POST);
echo '</pre>';

} else {

echo 'Submit button has not been pressed!<br /><br /><br />';

}

?>


<form action="" method="post">

<input type="text" name="textbox_sample" /><br />
<br />
<input type="password" name="password_sample" /><br />
<br />
<input type="radio" name="radio_sample" value="val1" />Value 1<br />
<input type="radio" name="radio_sample" value="val2" />Value 2<br />
<input type="radio" name="radio_sample" value="val3" />Value 3<br />
<br />
<input type="checkbox" name="check_sample[]" value="chk1" />Check 1<br />
<input type="checkbox" name="check_sample[]" value="chk2" />Check 2<br />
<input type="checkbox" name="check_sample[]" value="chk3" />Check 3<br />
<br />
<textarea name="textarea_sample"></textarea><br />
<br />
<select name="selectbox_sample">
<option value="sel1">Select 1</option>
<option value="sel2">Select 2</option>
<option value="sel3">Select 3</option>
</select><br />
<br />
<input type="submit" name="submit" />

</form>

<br /><br /><br />
<a href="<?php echo $_SERVER['SCRIPT_NAME']; ?>">Reset</a>

 

It will help you better understand how forms work with php

Link to comment
Share on other sites

The landing page has a table that shows all the titles and people. Beside each movie title and person there is a link for edit or delete. Above the group is a link for add. What I'm showing you in this post is the middle page. An id is passed from the landing page to this one. I'm having a hard time getting that if statement below the select statment to work. The page I posted on the first post is showing the edit form populated with data.

Link to comment
Share on other sites

I really don't see an if statement after a select statement. Are you referring to the select element?

 

The logic is really hard to follow in your code. Perhaps comments saying what you are trying to do in your actual code will help out.

 

Im not sure if you're aware, but the form must be submitted via POST before PHP will populate the $_POST superglobal

Link to comment
Share on other sites

There is a post in there. Its after all the php in the form tag.

 

<?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")

{

    $isactor = 1;

}

else

}

  $isactor = 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>

Link to comment
Share on other sites

Thanks for all your wonderul help. Sit on this bloody forum for 6 hrs and nothing thanks for everything.

 

You've probably just lost all help from that. You should place your code in [.code] tags so people can read it better and do a little debugging variables along your code to see where the error is happening also.

Link to comment
Share on other sites

trie this as an example ok..........

 

does work..............

 

ps. where here to help those helping there self aswell

,so please read the web site guide lines ok.

 

<?php

$people_isactor="no";

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

     $isactor = 1;
     
}else{

   $isactor = 0;

}

echo $isactor;

?>

Link to comment
Share on other sites

Here a 1 min example ok...

 

 

redesign your code CLUE ($_POST)

<?php

if($_POST['submit']){

$people_isactor=$_POST['people_isactor'];

if ($people_isactor == "yes"){

     $isactor = 1;
     
}else{

   $isactor = 0;

}

echo $isactor;
}
?>

<form method="POST" action="">

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

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

</select>

</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.