[SOLVED] $form['id'] not being selected :(
Posted: Fri Feb 25, 2005 10:48 am
Ok, I'm new to both the DevNetwork forums and PHP so flame away
Anyways, I'm trying to make a small script but I suck so I can't get it to work.
What it supposed to do is just find a person in a database via an id number provided in the address bar (i.e. edit.php?id=7 ), edit it, then thats it. It will get everything fine but when I try to submit, it comes up with the echo 'the request is missing data';
Any help would be greatly appreciated!
Here's the code...
What it supposed to do is just find a person in a database via an id number provided in the address bar (i.e. edit.php?id=7 ), edit it, then thats it. It will get everything fine but when I try to submit, it comes up with the echo 'the request is missing data';
Any help would be greatly appreciated!
Here's the code...
Code: Select all
<?
include_once ( 'config.php' );
if ( isset ( $_REQUESTї'id'] ) && ! empty ( $_REQUESTї'id'] ) )
{
if ( strtolower ( $_SERVERї'REQUESTED_METHOD'] ) == 'post' )
{
$query = array ();
if ( isset ( $_POSTї'firstname'] ) && ! empty ( $_POSTї'firstname'] ) )
{
$queryї] = "firstname = '" . mysql_real_escape_string ( $_POSTї'firstname'] ) . "'";
}
if ( isset ( $_POSTї'lastname'] ) && ! empty ( $_POSTї'lastname'] ) )
{
$queryї] = "lastname = '" . mysql_real_escape_string ( $_POSTї'lastname'] ) . "'";
}
if ( isset ( $_POSTї'email'] ) && ! empty ( $_POSTї'email'] ) )
{
$queryї] = "email = '" . mysql_real_escape_string ( $_POSTї'email'] ) . "'";
}
if ( ! empty ( $query ) )
{
$result = "UPDATE clients SET " . implode ( ', ', $query ) . " WHERE id = '" . mysql_real_escape_string ( $_REQUESTї'id'] ) . "'";
mysql_query ( $result ) or die ( 'UPDATE ERROR: ' . mysql_error () );
echo '<b>Thank you! client UPDATED Successfully!<br>';
echo '<meta http-equiv=Refresh content=2;url=index.php>';
}
else
{
echo 'the request did not contain any valid data, try again';
echo '<meta http-equiv=Refresh content=2;url=' . $SERVERї'PHP_SELF'] . '?id=' . $_REQUESTї'id'] .'>';
}
}
else
{
$result = "SELECT firstname, lastname, email FROM clients WHERE id = " . (int)$_REQUESTї'id'];
$r = mysql_query ( $result ) or die ( 'SELECT ERROR: ' . mysql_error () );
if ( mysql_num_rows ( $r ) > 0 )
{
$form = mysql_fetch_assoc ( $r );
?>
<h3>Edit Clients</h3>
<form method="post" action="<?=$_SERVERї'PHP_SELF'];?>">
<input type="hidden" name="id" value="<?=$formї'id'];?>">
firstname: <input name="firstname" size="50" maxlength="50" value="<?=htmlentities($formї'firstname']);?>">
<br>
lastname: <input name="lastname" size="50" maxlength="50" value="<?=htmlentities($formї'lastname']);?>">
<br>
email: <input name="email" size="50" maxlength="50" value="<?=htmlentities($formї'email']);?>">
<br>
<input type="submit" name="submit" value="Update Client">
</form>
<?
}
else
{
die ( 'QUERY ERROR: the id is not valid' );
}
}
}
else
{
echo 'the request is missing data';
}
?>