Code Error: Variable not being picked up?
Posted: Mon Jul 14, 2003 1:12 pm
Here is my code. The comments explain what I'm trying to do - but it wont' accept the value username.. instead it's treating it like it wants to insert a new user. I'm passing username to the function everytime, I don't know why it's not recognizing it.. username is a single variable, for example: r0ssta. Any ideaS?
[Admin Edit: Added PHP code tags]
Code: Select all
<?php
require_once('db_fns.php');
function display_user_form($username)
// This form can be used for inserting or editing information.
// To insert, don't pass any parameters. This will set $edit
// to false, and the form will go to insert_user.php.
// To update, pass an array containing a username. The
// form will be displayed with the old data and point to edit_user.php.
// It will also add a "Delete user" button.
{
// if passed an existing book, proceed in "edit mode"
$edit = is_array($username);
// most of the form is in plain HTML with some
// optional PHP bits throughout
?>
<form method=post
action="<?php echo $edit?'edit_user.php':'insert_user.php';?>">
<table border=0>
<tr>
<td>Username:</td>
<td><input type=text name=username
value="<?php echo $edit?$username['username']:''; ?>"></td>
</tr>
<tr>
<td>Title:</td>
<td><input type=text name=title
value="<?php echo $edit?$username['title']:''; ?>"></td>
</tr>
<tr>
<td>First Name:</td>
<td><input type=text name=firstName
value="<?php echo $edit?$username['firstName']:''; ?>"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type=text name=lastName
value="<?php echo $edit?$username['lastName']:''; ?>"></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type=text name=phone
value="<?php echo $edit?$username['phone']:''; ?>"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type=text name=email
value="<?php echo $edit?$username['email']:''; ?>"></td>
</tr>
<tr>
<td <?php if (!$edit) echo 'colspan=2'; ?> align=center>
<?php
if ($edit)
echo '<input type=hidden name=username
value="'.$username['username'].'">';
?>
<input type=submit
value="<?php echo $edit?'Update':'Add'; ?> Username">
</form></td>
<?php
if ($edit)
{
echo '<td>';
echo '<form method=post action="delete_user.php">';
echo '<input type=hidden name=username
value="'.$username['username'].'">';
echo '<input type=submit
value="Delete user.">';
echo '</form></td>';
}
?>
</td>
</tr>
</table>
</form>
<?php
}
?>